WPF DataGrid 不会在拖动时滚动
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
愚蠢的错误,ScrollViewer.IsDeferredScrollingEnabled =“True”是导致我的问题的原因
Stupid mistake, ScrollViewer.IsDeferredScrollingEnabled="True" is what was causing my problem
为数据网格实现以下两个属性:
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