0

所以我构建了一个漂亮的嵌套数据网格,看起来像这样:

<dg:DataGrid x:Name="mainGrid"
                AutoGenerateColumns="False" 
                CanUserAddRows="False"
                AreRowDetailsFrozen="True"
                CanUserReorderColumns="False"
                CanUserResizeColumns="True"
                CanUserResizeRows="False"
                SelectionUnit="FullRow"
                RowDetailsVisibilityMode="VisibleWhenSelected">
                <dg:DataGrid.Columns>
                    <dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="36" IsReadOnly="False">
                        <dg:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="+" Width="28" Height="28" />
                            </DataTemplate>
                        </dg:DataGridTemplateColumn.CellTemplate>
                    </dg:DataGridTemplateColumn>
                    <dg:DataGridTemplateColumn>
                        <dg:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"/>
                                </Grid>
                            </DataTemplate>
                        </dg:DataGridTemplateColumn.CellTemplate>
                    </dg:DataGridTemplateColumn>
                    <dg:DataGridTemplateColumn Header="Name" IsReadOnly="True" Width="582">
                        <dg:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=Default}" />
                            </DataTemplate>
                        </dg:DataGridTemplateColumn.CellTemplate>
                    </dg:DataGridTemplateColumn>
                    <dg:DataGridTemplateColumn Header="Status" IsReadOnly="True" Width="150">
                        <dg:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding Status, Mode=TwoWay, UpdateSourceTrigger=Default}" />
                            </DataTemplate>
                        </dg:DataGridTemplateColumn.CellTemplate>
                    </dg:DataGridTemplateColumn>
                    <dg:DataGridCheckBoxColumn Binding="{Binding IsSelected}"/>
                </dg:DataGrid.Columns>
                <dg:DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <dg:DataGrid x:Name="scondaryDatagrid" Margin="29,0,0,0" 
                            AutoGenerateColumns="False" 
                            CanUserAddRows="False"
                            AreRowDetailsFrozen="True"
                            CanUserReorderColumns="False"
                            CanUserResizeColumns="True"
                            CanUserResizeRows="False"
                            SelectionUnit="Cell"
                            RowDetailsVisibilityMode="VisibleWhenSelected"
                            ItemsSource="{Binding Grades, Mode=TwoWay}">
                            <dg:DataGrid.Columns>
                                <dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="32" IsReadOnly="True">
                                    <dg:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Button Content="+" Width="28" Height="28" />
                                        </DataTemplate>
                                    </dg:DataGridTemplateColumn.CellTemplate>
                                </dg:DataGridTemplateColumn>
                                <dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="32" IsReadOnly="True">
                                    <dg:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center" />
                                        </DataTemplate>
                                    </dg:DataGridTemplateColumn.CellTemplate>
                                </dg:DataGridTemplateColumn>
                                <dg:DataGridTemplateColumn Header="Name" IsReadOnly="True" Width="550">
                                    <dg:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Margin="5" Text="{Binding Name, Mode=TwoWay}" VerticalAlignment="Center" />
                                        </DataTemplate>
                                    </dg:DataGridTemplateColumn.CellTemplate>
                                </dg:DataGridTemplateColumn>
                            </dg:DataGrid.Columns>
                            <dg:DataGrid.RowDetailsTemplate>
                                <DataTemplate>
                                    <dg:DataGrid Margin="25,0,0,0" 
                                        AutoGenerateColumns="False" 
                                        CanUserAddRows="False"
                                        AreRowDetailsFrozen="True"
                                        CanUserReorderColumns="False"
                                        CanUserResizeColumns="True"
                                        CanUserResizeRows="False"
                                        SelectionUnit="Cell"
                                        ItemsSource="{Binding Notes, Mode=TwoWay}">
                                        <dg:DataGrid.Columns>
                                            <dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="32" IsReadOnly="True">
                                                <dg:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                                                    </DataTemplate>
                                                </dg:DataGridTemplateColumn.CellTemplate>
                                            </dg:DataGridTemplateColumn>
                                            <dg:DataGridTemplateColumn Header="Note" IsReadOnly="True" Width="550">
                                                <dg:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBlock Margin="5" Text="{Binding Note, Mode=TwoWay}" VerticalAlignment="Center" />
                                                    </DataTemplate>
                                                </dg:DataGridTemplateColumn.CellTemplate>
                                            </dg:DataGridTemplateColumn>
                                        </dg:DataGrid.Columns>
                                    </dg:DataGrid>
                                </DataTemplate>
                            </dg:DataGrid.RowDetailsTemplate>
                        </dg:DataGrid>
                    </DataTemplate>
                </dg:DataGrid.RowDetailsTemplate>


            </dg:DataGrid>

由于 RowDetailsVisibilityMode 属性设置为 VisibleWhenSelected 时,行的节点 DataGridDetailsPresenter 有 0 个子节点。当属性设置为可见时,我可以看到 DataGridDetailsPresenter 子级。

当 RowDetailsVisibilityMode 属性为 VisibleWhenSelected 时,如何强制包含可视树中的所有节点?

非常感谢任何输入。

4

1 回答 1

1

你想达到什么目的?

除非 RowDetails 可见,否则它们不会出现在 Visual Tree 中,除非可以通过将 RowDetailsVisibilityMode 设置为 Visible 但将 RowDetails DataGrid 可见性设置为 Collapsed 来强制创建它们。这可能行不通。如果在 3.5 中设置为 Collapsed,我不知道 DataGrid 是否会出现在 Visual Tree 中。

于 2011-09-08T16:36:17.480 回答