I’m creating a WPF View with a DataGrid.
The DataGrid is bound to the field Properties on the ViewModel.
However, for one of the columns I want each row to have the same value bound to some other property on the View model.
Specificically, the table is showing named monetary values and the repeated column will show a currency code (which is the same for each row).
I can’t figure out how to do this, I’ve tried to use the following:
<DataGrid ItemsSource="{Binding Properties}">
<DataGrid.Columns>
<DataGridTextColumn Header="Target" Binding="{Binding Target}"/>
<DataGridTextColumn Header="Value" Binding="{Binding Value}"/>
<DataGridTemplateColumn Header="Currency">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Properties.NodeCurrency}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
I’m using the Caliburn framework with no typed DataContext in the View. I’m not sure if this matters to the question though.
With assistance from both answerers the actual binding I needed was:
The missing bit was specifying that I’m binding to the
DataContextof theUserControland then delving down into the properties on theViewModel.