选项卡控件和预先存在的数据视图

本文关键字:存在 数据 视图 控件 选项 | 更新日期: 2023-09-27 18:03:03

我有一个wpf表单上的数据网格。我需要的是有这个数据网格驻留在一个选项卡控件。是否有可能通过篡改xaml来实现这一点,或者我是否必须删除数据网格,然后添加选项卡控件,然后在选项卡控件中重做数据网格?我尝试在标签之间封装数据网格xaml,但没有给它任何维度。没有得到所需的结果。

这里是数据网格xaml

<DataGrid x:Name="_dgvInventory"
                                         VirtualizingStackPanel.IsVirtualizing="True"
                                         VirtualizingStackPanel.VirtualizationMode="Recycling"
                                         Grid.Row="1"
                                         AutoGenerateColumns="False"
                                         ItemsSource="{Binding}"
                                         IsReadOnly="True"
                                         SelectionMode="Single"
                                         SelectionUnit="FullRow"
                                         RowHeaderWidth="30"
                                         SelectionChanged="DGVInventory_SelectionChanged"
                                         LoadingRow="DataGridLoadingRow"
                                         VerticalScrollBarVisibility="Auto"
                                         HorizontalScrollBarVisibility="Auto">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="Status"
                                                              Binding="{Binding Status}"/>
                                    <DataGridTextColumn Header="Tag ID"
                                                              Binding="{Binding TagId}"/>
                                    <DataGridTextColumn Header="Description"
                                                              Binding="{Binding Description}"/>
                                    <DataGridTextColumn Header="Part Number"
                                                              Binding="{Binding PartNumber}"/>
                                    <DataGridTextColumn Header="Serial Number"
                                                              Binding="{Binding SerialNumber}"/>
                                    <DataGridTextColumn Header="Location"
                                                              Binding="{Binding Location}"/>
                                    <DataGridTextColumn Header="Room"
                                                              Binding="{Binding Room}"/>
                                    <DataGridTextColumn Header="Inventory"
                                                              Binding="{Binding Inventory}"/>
                                    <DataGridTextColumn Header="Comment"
                                                              Binding="{Binding OwnedComment}"/>
                                </DataGrid.Columns>
                                <DataGrid.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Header="Search"
                                                     Click="SearchParts_Click" />
                                        <MenuItem Header="Masked Search" Click="MaskedSearchMenuItem_Click"/>
                                    </ContextMenu>
                                </DataGrid.ContextMenu>
                                <DataGrid.RowStyle>
                                    <Style TargetType="{x:Type DataGridRow}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Status}"
                                                             Value="Inv:found">
                                                <Setter Property="Background"
                                                          Value="GreenYellow"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Status}"
                                                             Value="Inv:unfound">
                                                <Setter Property="Background"
                                                          Value="Salmon"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Status}"
                                                             Value="unknown">
                                                <Setter Property="Background"
                                                          Value="Yellow"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Status}"
                                                             Value="stray">
                                                <Setter Property="Background"
                                                          Value="LightBlue"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </DataGrid.RowStyle>
                            </DataGrid>

它存在于wpf窗口选项卡控件中。选项卡控件上有一些其他的数据网格和滑动条等等。我需要做的就是把这个特定的数据网格放在一个标签控件上,它本身就在主标签控件中。我希望我的问题更清楚。我想知道是否在xaml中我可以做一些简单的事情,并创建迷你tabcontrol和"滑动"它背后的数据网格(这将是一个孩子的迷你选项卡控件)。如果我的术语不是公认的标准,我道歉。

选项卡控件和预先存在的数据视图

我想这就是你想要的……

<TabControl HorizontalAlignment="Left" Height="250" Margin="0,10,0,0" VerticalAlignment="Top" Width="292">
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5">
                <TabControl>
                    <TabItem Header="TabItem">
                        <Grid>
                            <DataGrid x:Name="_dgvInventory"
                                     VirtualizingStackPanel.IsVirtualizing="True"
                                     VirtualizingStackPanel.VirtualizationMode="Recycling"
                                     Grid.Row="1"
                                     AutoGenerateColumns="False"
                                     ItemsSource="{Binding}"
                                     IsReadOnly="True"
                                     SelectionMode="Single"
                                     SelectionUnit="FullRow"
                                     RowHeaderWidth="30"
                                     SelectionChanged="DGVInventory_SelectionChanged"
                                     LoadingRow="DataGridLoadingRow"
                                     VerticalScrollBarVisibility="Auto"
                                     HorizontalScrollBarVisibility="Auto">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="Status"
                                                          Binding="{Binding Status}"/>
                                    <DataGridTextColumn Header="Tag ID"
                                                          Binding="{Binding TagId}"/>
                                    <DataGridTextColumn Header="Description"
                                                          Binding="{Binding Description}"/>
                                    <DataGridTextColumn Header="Part Number"
                                                          Binding="{Binding PartNumber}"/>
                                    <DataGridTextColumn Header="Serial Number"
                                                          Binding="{Binding SerialNumber}"/>
                                    <DataGridTextColumn Header="Location"
                                                          Binding="{Binding Location}"/>
                                    <DataGridTextColumn Header="Room"
                                                          Binding="{Binding Room}"/>
                                    <DataGridTextColumn Header="Inventory"
                                                          Binding="{Binding Inventory}"/>
                                    <DataGridTextColumn Header="Comment"
                                                          Binding="{Binding OwnedComment}"/>
                                </DataGrid.Columns>
                                <DataGrid.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Header="Search"
                                                 Click="SearchParts_Click" />
                                        <MenuItem Header="Masked Search" Click="MaskedSearchMenuItem_Click"/>
                                    </ContextMenu>
                                </DataGrid.ContextMenu>
                                <DataGrid.RowStyle>
                                    <Style TargetType="{x:Type DataGridRow}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Status}"
                                                         Value="Inv:found">
                                                <Setter Property="Background"
                                                      Value="GreenYellow"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Status}"
                                                         Value="Inv:unfound">
                                                <Setter Property="Background"
                                                      Value="Salmon"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Status}"
                                                         Value="unknown">
                                                <Setter Property="Background"
                                                      Value="Yellow"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Status}"
                                                         Value="stray">
                                                <Setter Property="Background"
                                                      Value="LightBlue"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </DataGrid.RowStyle>
                            </DataGrid>
                        </Grid>
                    </TabItem>
                </TabControl>
            </Grid>
        </TabItem>
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5"/>
        </TabItem>
    </TabControl>

我注意到,当我把子TabControl拖到父TabControl中时,它根本没有出现任何Items。然后你需要在每个项目中使用一个网格