子曾经曰过

  博客园  :: 首页  ::  ::  ::  :: 管理
View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;

namespace WpfApplication2
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
//listBox1.SelectedValue 是一个Person类型
button1.Content = (listBox1.SelectedValue as Person).name;
}
}
public class photo : List<Person>
{
public photo()
{
Add(
new Person("张三", @"d:\temp\1.png"));
Add(
new Person("李四", @"d:\temp\j.png"));
Add(
new Person("王五", @"d:\temp\person.png"));
Add(
new Person("赵六", @"d:\temp\s.png"));
}
}
public class Person
{
public string name;
public string imgurl;
public Person()
{ }
public Person(string value1, string value2)
{
this.name = value1;
this.imgurl = value2;
}
public string PersonName
{
get { return name; }
set { name = value; }
}
public string ImgUrl
{
get { return imgurl; }
set { imgurl = value; }
}
}
}
View Code
<Window x:Class="WpfApplication2.Window1"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src
="clr-namespace:WpfApplication2"
Title
="Window1" Height="350" Width="500">
<Grid Name="Grid1">
<Grid.Resources>
<src:photo x:Key="datas"></src:photo>
<DataTemplate x:Key="imgtemplate">
<DockPanel>
<Image Width="50" Height="50" Source="{Binding Path=ImgUrl}"/>
<TextBlock Foreground="Red" FontSize="28">
<TextBlock.Text><Binding Path="PersonName"></Binding></TextBlock.Text>
</TextBlock>
</DockPanel>
</DataTemplate>
</Grid.Resources>
<ListBox ItemTemplate="{StaticResource imgtemplate}" Margin="12,12,0,0" Name="listBox1" Height="94" VerticalAlignment="Top" HorizontalAlignment="Left" Width="155">
<ListBox.ItemsSource>
<Binding Source="{StaticResource datas}"></Binding>
</ListBox.ItemsSource>
</ListBox>
<Button Height="26" HorizontalAlignment="Right" Margin="0,12,41,0" Name="button1" VerticalAlignment="Top" Width="88" Click="button1_Click">选中内容</Button>
</Grid>
</Window>
posted on 2011-03-02 15:08  人的本质是什么?  阅读(1382)  评论(0编辑  收藏  举报