1

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 
7
  • You have define two columns only. So, what else you expect? Commented Jan 3, 2014 at 13:46
  • A RowHeader populated for the string in Item.Item1? Commented Jan 3, 2014 at 14:03
  • Your code works for me Commented Jan 3, 2014 at 14:40
  • @Shoe you can see the RowHeader string? Commented Jan 3, 2014 at 15:09
  • Yes, you might try putting static text in there to see if you can see text at all. Commented Jan 3, 2014 at 15:16

2 Answers 2

2

I ran into this issue as well. The "HeaderVisibility" may be defaulting to column.

<DataGrid 
         Grid.Column="0" 
         ItemsSource="{Binding Path=Results}" 
         Margin="5"
         HeadersVisibility="All"
         >

Sign up to request clarification or add additional context in comments.

Comments

1

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>
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.