WPF中使用ItemsControl嵌套绑定,在ItemsControl中嵌套一个ItemsControl,然后使用绑定
2012-09-13 17:38
447 查看
最需要注意的一点是,绑定一定要使用属性,因为属性提供{set;get;}方法。
XAML中的定义:
注意:需要在第二层ItemsControl的ItemsSource绑定的内容
CS文件的内容:
第三部分:
Person类的定义
以上,
XAML中的定义:
注意:需要在第二层ItemsControl的ItemsSource绑定的内容
<Window x:Class="Binding_Demo_01.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <ItemsControl x:Name="list1"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Center"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding CurrPerson}" MouseDoubleClick="ItemsControl_MouseDoubleClick"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Center"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"> <Image Source="{Binding Image}" Stretch="UniformToFill" Height="400" Width="230" Margin="4"/> <TextBlock Text="{Binding Name}" Margin="4"/> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> </Window>
CS文件的内容:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); ObservableCollection<Persons> persons = new ObservableCollection<Persons> { new Persons { CurrPerson = new List<Person> { new Person{Name="Chrysanthemum", Age=21, Email="chrysanthemum@gmail.com", Image="Chrysanthemum.jpg"}, new Person{Name="Desert", Age=23, Email="Desert@gmail.com", Image="Desert.jpg"} } }, new Persons { CurrPerson = new List<Person> { new Person{Name="Jellyfish", Age=32, Email="Jellyfish@gmail.com", Image="Jellyfish.jpg"}, new Person{Name="Hydrangeas", Age=23, Email="Hydrangeas@gmail.com", Image="Hydrangeas.jpg"} } } }; list1.ItemsSource = persons; } private void ItemsControl_MouseDoubleClick(object sender, MouseButtonEventArgs e) { } }
第三部分:
Person类的定义
class Person { public string Name { get; set; } public int Age { set; get; } public string Image { set; get; } public string Email { set; get; } } class Persons { public List<Person> CurrPerson { set; get; } }
以上,
相关文章推荐
- WPF中使用ItemsControl嵌套绑定,在ItemsControl中嵌套一个ItemsControl,然后使用绑定(2)
- 使用XIB自定义一个UIView,然后将这个view添加到controller的view 上(相当于所有界面都通过xib来实现)
- wpf资源嵌套,一个资源引用另外一个资源,被引用的资源应该声明在前面
- WPF使用异步绑定数据
- Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定之二:使用外部URL的XML文件)
- 使用微软Kinect进行手势识别操作的一个简单范例(WPF-C#)
- bonding-多网卡绑定一起,作为一个网卡使用,实现负载均衡和提高带宽
- 有一个字符串s,t,d,g,h,m怎么把他转换成数组然后排序!(split的使用)
- 11-28 自己写一个数据集DataSet---ds,向其中添加一个数据表DataTable ---dt,并创建该表的列和行。然后将本本表作为数据源绑定到GradView中。
- 使用Jquery提交POST请求,然后进行报表展示的一个示例
- 新建一个win32空工程,然后使用MFC创建程序
- SpringMVC3,使用RequestMappint的Param参数,实现一个url绑定多个方法
- 编程序将一个字符串的前N个子字符送到一个字符型数组中去,然后再加上一个'\0'(不允许使用strcoy(str1,str2,n)函数)。
- WPF一个绑定格式化显示的写法
- iOS开发UI基础—21使用嵌套模型完成的一个简单汽车图标展示程序
- 输入一个Email地址,然后使用正则表达式验证该Email地址是否正确。
- (译)Silverlight教程第八部分:使用WPF创建一个Digg桌面应用
- Silverlight教程第八部分:使用WPF创建一个Digg桌面应用
- 动态DNS——本质上是IP变化,将任意变换的IP地址绑定给一个固定的二级域名。不管这个线路的IP地址怎样变化,因特网用户还是可以使用这个固定的域名 这样看的话,p2p可以用哇
- WPF 中双向绑定通知机制之ObservableCollection使用