I am trying to use a RowHeader
in a wpf
DataGrid
with no luck.
I followed this post
My XAML code
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<DataGrid Grid.Column="0" ItemsSource="{Binding Path=Results}" Margin="5">
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type DataGridRow}},
Path=Item.Item1}"/>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
<DataGrid.Columns>
<DataGridTextColumn Header="LArmAngle"
Binding="{Binding Item2.LArmAngle}" />
<DataGridTextColumn Header="PropellerAngle"
Binding="{Binding Item2.PropellerAngle}" />
</DataGrid.Columns>
</DataGrid>
...
</Grid>
The Results property is specified as follows
public ObservableCollection<Tuple<String, GeometryStateViewModel>> Results
{
get;
set;
}
I only see the two columns LArmAngle
and PropellerAngle
is the resulting DataGrid
.
I would like to see the following:
LArmAngle PropellerAngle
aStringHere 1 0.3
aStringHere 1 0.3
I was unable to find why I can not display the RowHeader. As a workaround I added an additional column in the data grid to display the sting that I wanted.
...
<DataGrid Grid.Column="0" ItemsSource="{Binding Path=Results}" Margin="5">
<DataGrid.Columns>
<DataGridTextColumn Header="Algorithm"
Binding="{Binding Item1}" />
<DataGridTextColumn Header="LArmAngle"
Binding="{Binding Item2.LArmAngle}" />
<DataGridTextColumn Header="PropellerAngle"
Binding="{Binding Item2.PropellerAngle}" />
</DataGrid.Columns>
</DataGrid>
...