Reputation: 1640
I have a List where a Person has Firstname and Surname. I want to concatenate Firstname and Surname to set combobox's itemsource and Display member Path.
Upvotes: 2
Views: 1100
Reputation: 1293
You can use DataTemplate
for Concatinating two properties.
For Example.
<ComboBox>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<Run Text="{Binding TaxName}" />
<Run Text=" | @" />
<Run FontWeight="Bold" Text="{Binding Rate}" />
<Run FontWeight="Bold" Text="%" />
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
it will be viewed as: Service Tax | @12.36%
and bind its value on the code behind as
cmbTax.ItemsSource = taxes;
cmbTax.SelectedValuePath = "TaxID";
Upvotes: 3
Reputation: 1138
Just create a view model, add a property with FirstName + Surname and use it in Display Member path.
Upvotes: 4