I have a ListBox which hold a set of objects (linked via ItemsSource bind to an ObservableCollection). I haven't used Dynamic binding yet. It currently use the ToString()
method of the object. The ToString() method shows a string this way : name (someOtherProperty)
However, even if the INotifyPropertyChanged is implemented and that i use an ObservableCollection, if i change an 开发者_如何学编程item property this string won't be updated.
I believe that this is because it only calls ToString
once. instead i guess i have to use data binding but how i can form such a string with it ? << name (someOtherProperty) >>
Thanks.
You can use a multibinding, e.g. something like this:
<MultiBinding StringFormat="{}{0} ({1})">
<Binding Path="name"/>
<Binding Path="someOtherProperty"/>
</MultiBinding>
If you just let it execute ToString there is no proper binding at all, any notifications will have no effect.
You use it like this:
<ListBox ...>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<!-- The above binding here -->
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
精彩评论