WPF DataGrid 不会在拖动时滚动

发布于 2024-08-27 19:41:40 字数 3610 浏览 6 评论 0原文

我对 WPF Toolkit 中的 WPF DataGrid 有一个奇怪的问题。当行数增加时,滚动条会正确显示,并且当您按滚动条上的向上或向下箭头时,滚动会起作用。

当我尝试拖动数据网格上的滚动条时,问题就出现了。我的页面周围有一个滚动查看器。当我单击并拖动网格上的滚动条时,它会滚动页面滚动条。如果页面上没有出现滚动条,则网格仍然不会滚动。有解决方法吗?

非常感谢有关此问题的一些帮助!

例如,在这种情况下,如果页面<< 280,拖动时滚动。但拖动滚动在网格上不起作用。

<ScrollViewer ScrollViewer.IsDeferredScrollingEnabled="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" >
                    <DockPanel>
                        <dg:DataGrid HorizontalScrollBarVisibility="Auto" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeColumns="False" CanUserSortColumns="False" AutoGenerateColumns="False" RowHeaderWidth="17" ItemsSource="{Binding Path=OrderSearchVm}" IsReadOnly="True" MaxHeight="280" DockPanel.Dock="Top">
                            <dg:DataGrid.Columns>                                   
                                <dg:DataGridTextColumn Width="75" Header="Date" Binding="{Binding Path=OrderDate}" >
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>
                                <dg:DataGridTextColumn Header="Type" Binding="{Binding Path=OrderType}" Width="45"/>
                                <dg:DataGridTextColumn Header="Shipping Name" Binding="{Binding Path=ShipToName}" Width="115">
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>
                                <dg:DataGridTextColumn Header="Shipping Address " Binding="{Binding Path=ShipToAddress}" Width="160">
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>                                   
                                <dg:DataGridTextColumn Header="E-Mail" Binding="{Binding Path=Email}" Width="140">
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>
                            </dg:DataGrid.Columns>
                        </dg:DataGrid>
                    </DockPanel>
    </ScrollViewer>

I have a strange problem with a WPF DataGrid from WPF Toolkit. The scrollbars appear correctly when the number of rows grows, and the scrolling works when you press up or down arrows on the scrollbar.

The problem comes in when I try to drag the scrollbar on the datagrid. My page has a scroll viewer around it. When I click and drag the scrollbar on the grid, it scrolls the page scroller instead. If the scrollbar does not apear on the page, there grid still does not scroll. Is there a workaround for this???

Would really appreciate some help with this issue!

For example, in this case if the page is < 280, it scrolls on drag. But drag scrolling does not work on the grid.

<ScrollViewer ScrollViewer.IsDeferredScrollingEnabled="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" >
                    <DockPanel>
                        <dg:DataGrid HorizontalScrollBarVisibility="Auto" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeColumns="False" CanUserSortColumns="False" AutoGenerateColumns="False" RowHeaderWidth="17" ItemsSource="{Binding Path=OrderSearchVm}" IsReadOnly="True" MaxHeight="280" DockPanel.Dock="Top">
                            <dg:DataGrid.Columns>                                   
                                <dg:DataGridTextColumn Width="75" Header="Date" Binding="{Binding Path=OrderDate}" >
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>
                                <dg:DataGridTextColumn Header="Type" Binding="{Binding Path=OrderType}" Width="45"/>
                                <dg:DataGridTextColumn Header="Shipping Name" Binding="{Binding Path=ShipToName}" Width="115">
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>
                                <dg:DataGridTextColumn Header="Shipping Address " Binding="{Binding Path=ShipToAddress}" Width="160">
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>                                   
                                <dg:DataGridTextColumn Header="E-Mail" Binding="{Binding Path=Email}" Width="140">
                                    <dg:DataGridTextColumn.ElementStyle>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextWrapping" Value="Wrap" />
                                        </Style>
                                    </dg:DataGridTextColumn.ElementStyle>
                                </dg:DataGridTextColumn>
                            </dg:DataGrid.Columns>
                        </dg:DataGrid>
                    </DockPanel>
    </ScrollViewer>

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

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

发布评论

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

评论(2

猫腻 2024-09-03 19:41:40

愚蠢的错误,ScrollViewer.IsDeferredScrollingEnabled =“True”是导致我的问题的原因

Stupid mistake, ScrollViewer.IsDeferredScrollingEnabled="True" is what was causing my problem

贱人配狗天长地久 2024-09-03 19:41:40

为数据网格实现以下两个属性:

  • ScrollViewer.IsDeferredScrollingEnabled="True"
  • ScrollMode="Deferred"

您将能够正确滚动数据网格

Implement follwoing two properties for data grid :

  • ScrollViewer.IsDeferredScrollingEnabled="True"
  • ScrollMode="Deferred"

You will be able to scroll properly for data grid

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