When binding, is it possible to specify the path on the source object?
In a given binding, is it possible to specify the path on the source object?
It seems like this could avoid a lot of trivial conver开发者_运维知识库ters.
Imagine the following example:
C#:
class foo
{
bool A
int B
}
WPF:
<ComboBox
ItemsSource="ListOfFoos"
SelectedItem="{Binding number, SourcePath=B}" />
I guess the SelectedValuePath property is what you are looking for. It's inherited from Selector, so it will work for ComboBoxes, ListBoxes, etc.
Cheers, Alex
2 options:
DisplayMemberPath="B"
property ofComboBox
- Custom template for each item
like this:
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding B}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
精彩评论