选项卡控件和预先存在的datagridview

时间:2013-03-07 18:22:04

标签: c# wpf

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

这是datagrid 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窗口选项卡控件上。选项卡控件上还有一些其他数据网格和滑块等。我需要做的是将一个特定的数据网格放在一个tabcontrol上,该tabcontrol本身就位于主标签控件中。我希望我的问题更清楚。我想知道如果在xaml中我可以做一些简单的事情并创建迷你tabcontrol并在数据网格后面“滑动”它(这将是迷你制表符控件的子项)。如果我的术语不是公认的规范,我会道歉。新的。

1 个答案:

答案 0 :(得分:1)

我认为这就是你之后......

<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拖到父级时,它显示没有任何项目。然后你需要在每个项目中都有一个网格。