绑定到字典值中的对象 [英] Binding to object in dictionary value
本文介绍了绑定到字典值中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关键Guid和网络类值的字典,我希望将ItemsControl项绑定到Dictionary中的Network类
这是xaml我有。
I have a dictionary of key Guid and a network class value, and I wish to bind the ItemsControl Items to the Network classes inside the Dictionary
Here is the xaml I have.
<ItemsControl ItemsSource="{Binding NetworkList}" x:Name="iclItems" Grid.Column="1" Grid.Row="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid removed="Orange" Width="250" Height="250" Margin="20">
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
这里的代码背后只添加一个网络到字典< br $> b $ b
And here is the code behind that adds just a Network to the dictionary
private Dictionary<Guid, Network> mdictNetworkList;
public Dictionary<Guid, Network> NetworkList
{
get { return mdictNetworkList; }
set { mdictNetworkList = value; }
}
public MainPage()
{
this.InitializeComponent();
mdictNetworkList = new Dictionary<Guid, Network>();
Network objNetwork = new Network();
mdictNetworkList.Add(objNetwork.ID, objNetwork);
}
我没有收到任何物品。有什么想法吗?如果之前有人问过这个问题我很抱歉,但是我无法找到解决问题的答案。
I''m not getting any items being added. Any ideas why? I''m sorry if this has been asked before, but I couldn''t find an answer to my problem that worked.
推荐答案
当<$的值时c $ c> NetworkList 正在改变然后你没有解雇RaisePropertyChanged
事件
例如
When the value ofNetworkList
is changing then you are not firingRaisePropertyChanged
event
e.g.
this.RaisePropertyChanged("NetworkList");
以及您在代码中绑定DataContext的位置?
and where you are binding the DataContext in your code?
this.DataContext = this;
这篇关于绑定到字典值中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文