带有数据分页器和网格分割器的 SL4 数据网格

发布于 2024-09-07 19:15:54 字数 5143 浏览 1 评论 0原文

我有一个包含两行和一个 GridSplitter 的网格。 在第一行中,我有一个 StackPanel,其中包含 DataPager 和 DataGrid。 在第二行中,我将扩展器控件垂直底部对齐,扩展方向向上。 DataGrid 将占据两行的所有空间(垂直拉伸),但当单击 Expander 标题时,它将向上扩展,DataGrid 将自动收缩。

但这并没有发生。当我单击扩展器时,它确实会扩展,但页面大小会增加,而不是 DataGrid(第 0 行)向上缩小。 有人知道我怎样才能实现这一目标吗? 我的代码如下。我尝试过将 ScrollViewers 置于 DataGrid 级别、StackPanel 级别以及 Grid 级别,但没有成功。

 <Grid x:Name="contentGrid" HorizontalAlignment="Stretch" Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <tools:GridSplitter x:Name="rowSplitter" Grid.Row="1"  VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <StackPanel Grid.Row="0" Orientation="Vertical" VerticalAlignment="Stretch" >
                    <StackPanel Orientation="Horizontal" Width="auto" Height="30">
                        <TextBlock Text="Search" Margin="20,10,0,0" TextAlignment="Center" VerticalAlignment="Center" Height="25"/>
                        <TextBox Width="200" Margin="5,0,0,0" x:Name="txtSearch" Height="25"/>
                        <ComboBox x:Name="cboFilter" SelectedIndex="0" SelectedValuePath="Name" VerticalAlignment="Center" Height="25">
                            <ComboBoxItem Name="Code">Line No</ComboBoxItem>
                            <ComboBoxItem Name="Description1">Heading</ComboBoxItem>
                            <ComboBoxItem Name="Description2">Happy Text</ComboBoxItem>
                            <ComboBoxItem Name="PromotionType">Promotion Type</ComboBoxItem>
                        </ComboBox>
                        <CheckBox x:Name="chkIsGrouping" Margin="10,5,0,0" Content="Enable Grouping" Checked="chkIsGrouping_Checked"/>
                         </StackPanel>
                    <sdk:DataPager Height="25" Name="dataPager1"  Source="{Binding ElementName=productDomainDataSource, Path=Data}" />

                    <sdk:DataGrid  AutoGenerateColumns="False"   HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" ItemsSource="{Binding ElementName=productDomainDataSource, Path=Data}" Name="productDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" SelectionChanged="productDataGrid_SelectionChanged" >
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTextColumn x:Name="codeColumn" Binding="{Binding Path=Code}" Header="Code" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="description1Column" Binding="{Binding Path=Description1}" Header="Description 1" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="description2Column" Binding="{Binding Path=Description2}" Header="Description 2" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="productIDColumn" Binding="{Binding Path=ProductID, Mode=OneWay}" Header="Product ID" IsReadOnly="True" Width="SizeToHeader" Visibility="Collapsed" />
                            <sdk:DataGridTextColumn x:Name="promotionIDColumn" Binding="{Binding Path=PromotionID}" Header="Promotion ID" Width="SizeToHeader" Visibility="Collapsed"/>
                            <sdk:DataGridTextColumn x:Name="promotionTypeIDColumn" Binding="{Binding Path=PromotionTypeID}" Header="Promotion Type ID" Width="SizeToHeader" Visibility="Collapsed" />
                            <sdk:DataGridTextColumn x:Name="retailPriceColumn" Binding="{Binding Path=RetailPrice}" Header="Retail Price" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="retailPriceUnitColumn" Binding="{Binding Path=RetailPriceUnit}" Header="Retail Price Unit" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="templateIDColumn" Binding="{Binding Path=TemplateID}" Header="Template ID" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="wasPriceColumn" Binding="{Binding Path=WasPrice}" Header="Was Price" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="wasPriceUnitColumn" Binding="{Binding Path=WasPriceUnit}" Header="Was Price Unit" Width="SizeToHeader" />
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>

                </StackPanel>
                </ScrollViewer>
                <expandertoolkit:Expander x:Name="Expander1" Margin="0,10,0,0" Grid.Row="1" VerticalAlignment="Bottom"
                       ExpandDirection="Up"
                       HeaderTemplate="{StaticResource DTHeader}"
                       ContentTemplate="{StaticResource DTContent}">

                    </expandertoolkit:Expander>
            </Grid>

I have a grid with two Rows and a GridSplitter.
In the first Row I have a StackPanel which has the DataPager and DataGrid in it.
In the second Row I have the Expander Control vertically bottom aligned and Expand Direction Upward.
The idea that the DataGrid will occupy all the space (vertically stretch) of both Rows but when the Expander header will be clicked, it will expand upward and DataGrid will shrink automatically.

But this is not happening. When I click on the expander, it does expand but the page size increase instead of DataGrid(Row 0) shrinks upward.
Anybody know How I can achieve that?
My Code is as below . I have tried by putting the ScrollViewers at DataGrid level, StackPanel level and also Grid level too but without success.

 <Grid x:Name="contentGrid" HorizontalAlignment="Stretch" Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <tools:GridSplitter x:Name="rowSplitter" Grid.Row="1"  VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <StackPanel Grid.Row="0" Orientation="Vertical" VerticalAlignment="Stretch" >
                    <StackPanel Orientation="Horizontal" Width="auto" Height="30">
                        <TextBlock Text="Search" Margin="20,10,0,0" TextAlignment="Center" VerticalAlignment="Center" Height="25"/>
                        <TextBox Width="200" Margin="5,0,0,0" x:Name="txtSearch" Height="25"/>
                        <ComboBox x:Name="cboFilter" SelectedIndex="0" SelectedValuePath="Name" VerticalAlignment="Center" Height="25">
                            <ComboBoxItem Name="Code">Line No</ComboBoxItem>
                            <ComboBoxItem Name="Description1">Heading</ComboBoxItem>
                            <ComboBoxItem Name="Description2">Happy Text</ComboBoxItem>
                            <ComboBoxItem Name="PromotionType">Promotion Type</ComboBoxItem>
                        </ComboBox>
                        <CheckBox x:Name="chkIsGrouping" Margin="10,5,0,0" Content="Enable Grouping" Checked="chkIsGrouping_Checked"/>
                         </StackPanel>
                    <sdk:DataPager Height="25" Name="dataPager1"  Source="{Binding ElementName=productDomainDataSource, Path=Data}" />

                    <sdk:DataGrid  AutoGenerateColumns="False"   HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" ItemsSource="{Binding ElementName=productDomainDataSource, Path=Data}" Name="productDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" SelectionChanged="productDataGrid_SelectionChanged" >
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTextColumn x:Name="codeColumn" Binding="{Binding Path=Code}" Header="Code" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="description1Column" Binding="{Binding Path=Description1}" Header="Description 1" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="description2Column" Binding="{Binding Path=Description2}" Header="Description 2" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="productIDColumn" Binding="{Binding Path=ProductID, Mode=OneWay}" Header="Product ID" IsReadOnly="True" Width="SizeToHeader" Visibility="Collapsed" />
                            <sdk:DataGridTextColumn x:Name="promotionIDColumn" Binding="{Binding Path=PromotionID}" Header="Promotion ID" Width="SizeToHeader" Visibility="Collapsed"/>
                            <sdk:DataGridTextColumn x:Name="promotionTypeIDColumn" Binding="{Binding Path=PromotionTypeID}" Header="Promotion Type ID" Width="SizeToHeader" Visibility="Collapsed" />
                            <sdk:DataGridTextColumn x:Name="retailPriceColumn" Binding="{Binding Path=RetailPrice}" Header="Retail Price" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="retailPriceUnitColumn" Binding="{Binding Path=RetailPriceUnit}" Header="Retail Price Unit" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="templateIDColumn" Binding="{Binding Path=TemplateID}" Header="Template ID" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="wasPriceColumn" Binding="{Binding Path=WasPrice}" Header="Was Price" Width="SizeToHeader" />
                            <sdk:DataGridTextColumn x:Name="wasPriceUnitColumn" Binding="{Binding Path=WasPriceUnit}" Header="Was Price Unit" Width="SizeToHeader" />
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>

                </StackPanel>
                </ScrollViewer>
                <expandertoolkit:Expander x:Name="Expander1" Margin="0,10,0,0" Grid.Row="1" VerticalAlignment="Bottom"
                       ExpandDirection="Up"
                       HeaderTemplate="{StaticResource DTHeader}"
                       ContentTemplate="{StaticResource DTContent}">

                    </expandertoolkit:Expander>
            </Grid>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-09-14 19:15:54

通常,如果您希望一行(例如底行)缩小另一行(例如顶行),则底行是自动调整大小,顶部是星形大小。

问题是,自动调整大小的行将适合其内容,而星形大小的行将仅占据其余部分,但如果没有任何东西限制整体大小,自动调整大小的行只会增长,而星形大小的行将占据它们所能容纳的一切适应他们的内容。

如果您想要您提到的折叠/增长行为,您需要设置控件的整体大小及其使用位置。

请注意,我无法弄清楚为什么您在该示例中有一个 Gridsplitter第一名,所以我可能会遗漏一些细节。

Normally if you want one row (say the bottom row) to shrink another (say the top row) then the bottom row is Auto-sized and the top is Star-sized.

The problem is that Auto-size rows will fit to their content and the Star sized will just grab the remainder, but if there is nothing restraining the overall size Auto-sized rows will just grow and the Star-sized rows will take whatever they can get to fit their content.

You need to set the overall size of the control, where it is used, if you want the collapse/grow behaviour you mention.

Please note I could not work out why you have a Gridsplitter in that example in the first place, so I may be missing some details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文