WPF DataGrid Multi level behaviour

Apr 8, 2010 at 9:47 AM
Edited Apr 8, 2010 at 9:49 AM

 

I have created multilevel Data grid using the RowDetailsTemplate i.e,

 Something like this:

 <toolkit:DataGrid
                                ToolTip="Hierarchy Data"
                                ItemsSource="{Binding HierarchyData}"
                                AutoGenerateColumns="False"
                                SelectionMode="Single">
                            <toolkit:DataGrid.Columns>
                                <toolkit:DataGridTemplateColumn CanUserResize="False">
                                    <toolkit:DataGridTemplateColumn.HeaderTemplate>
                                        <DataTemplate>
                                            <Image Source="xx" />
                                        </DataTemplate>
                                    </toolkit:DataGridTemplateColumn.HeaderTemplate>
                                    <toolkit:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock>
                                <Button Command="{Binding ViewRiskTypeCommand}" --this Command with make RowDetailsTemplate Visibleor Collapse
                                        CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=toolkit:DataGrid}, Path=SelectedItem}"
                                        Cursor="Hand">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Image Margin="2" Source="{Binding ImagePath}" />
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                            </TextBlock>
                                        </DataTemplate>
                                    </toolkit:DataGridTemplateColumn.CellTemplate>
                                </toolkit:DataGridTemplateColumn>
                                <toolkit:DataGridTextColumn Header="Risk Class"
                               Binding="{Binding Name}"
                               IsReadOnly="True" CanUserSort="True"></toolkit:DataGridTextColumn>
                            </toolkit:DataGrid.Columns>
                            <toolkit:DataGrid.RowDetailsTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                    <toolkit:DataGrid Margin="20,0,0,0"
                                          AutoGenerateColumns="False"
                                          SelectionMode="Single"
                                          RowStyle="{StaticResource RiskTypeMenu}"
                                          ItemsSource="{Binding RiskTypes}">
                                        <toolkit:DataGrid.Columns>
                                            <toolkit:DataGridTemplateColumn CanUserResize="False">
                                                <toolkit:DataGridTemplateColumn.HeaderTemplate>
                                                    <DataTemplate>
                                                        <Image Source="xx" />
                                                    </DataTemplate>
                                                </toolkit:DataGridTemplateColumn.HeaderTemplate>
                                                <toolkit:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBlock>
                                                <Button Command="{Binding ViewInstrumentTypeCommand}" --this Command with make RowDetailsTemplate Visibleor Collapse
                                                        CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=toolkit:DataGrid}, Path=SelectedItem}"
                                                        Cursor="Hand">
                                                    <Button.Template>
                                                        <ControlTemplate>
                                                            <Image Margin="2" Source="{Binding ImagePath}" />
                                                        </ControlTemplate>
                                                    </Button.Template>
                                                </Button>
                                            </TextBlock>
                                                    </DataTemplate>
                                                </toolkit:DataGridTemplateColumn.CellTemplate>
                                            </toolkit:DataGridTemplateColumn>
                                            <toolkit:DataGridTextColumn Header="Risk Type"
                                                                   Binding="{Binding Name}"
                                                                   IsReadOnly="True"/>
                                        </toolkit:DataGrid.Columns>
                                        <toolkit:DataGrid.RowDetailsTemplate>
                                            <DataTemplate>
                                                    <StackPanel>
                                                        <toolkit:DataGrid Margin="20,0,0,0"
                                                      AutoGenerateColumns="False"
                                                      RowStyle="{StaticResource InstrumentTypeMenu}"
                                                      ItemsSource="{Binding InstrumentTypes}">
                                                            <toolkit:DataGrid.Columns>
                                                                <toolkit:DataGridTemplateColumn CanUserResize="False">
                                                                    <toolkit:DataGridTemplateColumn.HeaderTemplate>
                                                                        <DataTemplate>
                                                                            <Image Source="xx" />
                                                                        </DataTemplate>
                                                                    </toolkit:DataGridTemplateColumn.HeaderTemplate>
                                                                    <toolkit:DataGridTemplateColumn.CellTemplate>
                                                                        <DataTemplate>
                                                                            <TextBlock>
                                                            <Button Command="{Binding ViewInstrumentsCommand}" --this Command with make RowDetailsTemplate Visibleor Collapse
                                                                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=toolkit:DataGrid}, Path=SelectedItem}"
                                                                    Cursor="Hand">
                                                                <Button.Template>
                                                                    <ControlTemplate>
                                                                        <Image Margin="2" Source="{Binding ImagePath}" />
                                                                    </ControlTemplate>
                                                                </Button.Template>
                                                            </Button>
                                                        </TextBlock>
                                                                        </DataTemplate>
                                                                    </toolkit:DataGridTemplateColumn.CellTemplate>
                                                                </toolkit:DataGridTemplateColumn>
                                                                <toolkit:DataGridTextColumn Header="Instrument Type"
                                                                   Binding="{Binding Name}"
                                                                   IsReadOnly="True"/>
                                                                <toolkit:DataGridTemplateColumn ClipboardContentBinding="{Binding Active}" IsReadOnly="True"  Header="Active">
                                                                    <toolkit:DataGridTemplateColumn.CellTemplate>
                                                                        <DataTemplate>
                                                                            <CheckBox HorizontalAlignment="Center" IsEnabled="False" IsChecked="{Binding Active, Mode=OneWay}">
                                                                            </CheckBox>
                                                                        </DataTemplate>
                                                                    </toolkit:DataGridTemplateColumn.CellTemplate>
                                                                </toolkit:DataGridTemplateColumn>                                                               
                                                            </toolkit:DataGrid.Columns>
                                                        </toolkit:DataGrid>
                                                    </StackPanel>
                                                </DataTemplate>
                                        </toolkit:DataGrid.RowDetailsTemplate>
                                    </toolkit:DataGrid>
                                    </StackPanel>
                                </DataTemplate>
                            </toolkit:DataGrid.RowDetailsTemplate>
                        </toolkit:DataGrid>

I have a Datagrid and have 3 sub datagrids under it in each of Row Details Template.

The problem is after expanding a sub grid and if I collapse the row grid again the actual desired height of the Grid does not change. Hence the above grid row that is below the collapsed row does not come up. Does any one have any solution for this.