的ItemsSource VS DataContext的WPF中
-
22-08-2019 - |
题
任何一个可以给我在WPF的ItemSource和ListView的DataContext的区别? 与实例
解决方案
在项目源(它必须impliment IEnumerable的) 将用来创建列表中出现的项目列表。在DataContext(其可以是任何对象)是绑定针对从而为已用于在ListView的其他属性中指定的任何绑定的缺省对象。
public List<string> ItemsObject = new List<string>() { "Item1", "Item2", "Item3" };
public AnyObject DataContextObject = new AnyObject() { WidthValue = 23 }
<ListView
ItemsSource="{Resource_of_ItemsObject}"
DataContext="{Resource_of_DataContextObject}"
Width="{Binding Path=WidthValue}"/>
将产生的23的宽度显示为“项目1”,项目2" ,项目3" 的列表。
不隶属于 StackOverflow