开发者

Binding listbox to underlying Value in a Dictionary

I am binding to an Observable Dictionary of type ObservableDictionary<int, Person> (although in this case I don't think it matters that it is Observ开发者_StackOverflow中文版able) and I can bind to this without an issue:

<ListBox x:Name="myListBox" ItemsSource="{Binding MyDictionary}">

However in my listbox template in order to access the underlying object I have to prefix all with value. Like the following:

<TextBlock x:Name="idValue" Text="{Binding Value.ID}" Grid.Column="2"/>

Which seems to work but what I was wondering is if it is possible to change the binding so that the Value prefix is unneeded? When I am using a data template it would feel better to me if it expected a type "Person"


Try using Dictionary.Values as item source :

<ListBox x:Name="myListBox" ItemsSource="{Binding MyDictionary.Values}">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜