嵌套在另一个数据网格的 RowDetailsTemplate 中的数据网格会中断鼠标滚轮滚动
我有一个 DataGrid“嵌套”在另一个 DataGrid 的 RowDetailsTemplate 中。每当我的鼠标位于父 DataGrid 上行的主要部分上时,滚动都可以正常工作,但是当鼠标位于嵌套在 RowDetailsTemplate 内的 DataGrid 上时,它会停止滚动。
这是 DataGrid 设置:
<my:DataGrid Margin="-2,36,-2,1"
Background="White"
CanUserReorderColumns="True"
CanUserResizeRows="False"
ColumnHeaderHeight="35"
HorizontalGridLinesBrush="LightGray"
VerticalGridLinesBrush="White"
x:Name="testList"
VerticalScrollBarVisibility="Visible"
FlowDirection="LeftToRight"
AutoGenerateColumns="False"
IsReadOnly="True"
ScrollViewer.CanContentScroll="False"
SelectionMode="Single"
HeadersVisibility="Column"
GridLinesVisibility="None"
>
<my:DataGrid.Columns>
<my:DataGridTemplateColumn MinWidth="60" CanUserSort="True" SortMemberPath="ResultType">
<my:DataGridTemplateColumn.Header>
<TextBlock FontSize="14" Text="Result"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="4" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Height="35" Width="35" Source="{Binding TestResultImage}" ToolTip="{Binding ResultType}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="100" CanUserSort="True" SortMemberPath="TestName">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="3" FontSize="14" Text="Dates"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock FontSize="14" TextWrapping="Wrap" AllowDrop="True" Text="{Binding TestName}" ToolTip="This test analyzed data from this date" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="150" Width="*" CanUserSort="True" x:Name="TestDetails" SortMemberPath="Result">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="4" FontSize="14" Text="Details"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5" VerticalAlignment="Center">
<TextBlock TextWrapping="Wrap" FontSize="13" Text="{Binding Result}" ToolTip="Click for more details about this test" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
<my:DataGrid.RowDetailsTemplate>
<DataTemplate>
<Grid>
<my:DataGrid Background="White"
BorderThickness="0"
CanUserReorderColumns="True"
HeadersVisibility="Column"
CanUserResizeRows="False"
ColumnHeaderHeight="25"
ItemsSource="{Binding GuiValidatorResults}"
HorizontalGridLinesBrush="LightGray"
x:Name="validatorList"
VerticalGridLinesBrush="White"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
FlowDirection="LeftToRight"
AutoGenerateColumns="False"
IsReadOnly="True"
ScrollViewer.CanContentScroll="False"
ScrollViewer.ScrollChanged=""
SelectionMode="Single"
MouseDoubleClick="HideAllValidatorDetails"
GridLinesVisibility="Horizontal">
<my:DataGrid.Columns>
<my:DataGridTemplateColumn MinWidth="60" CanUserSort="True" SortMemberPath="ResultType">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="0" Text="Result"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="0">
<Image Height="25" Width="25" Source="{Binding ValidatorResultImage}" ToolTip="{Binding ResultType}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="100" CanUserSort="True" SortMemberPath="DescriptiveTestLabel">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="0" Text="Validator"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5">
<TextBlock TextWrapping="Wrap" AllowDrop="True" Text="{Binding DescriptiveTestLabel}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="150" Width="*" CanUserSort="True" SortMemberPath="Text">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="0" Text="Message"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5">
<TextBlock TextWrapping="Wrap" AllowDrop="True" Text="{Binding Text}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
<my:DataGrid.RowDetailsTemplate>
<DataTemplate>
<GroupBox FontWeight="Bold" Margin="5" Header="Additional Details:">
<Grid Margin="5" x:Name="WidthSetter">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Resources>
<DataTemplate x:Key="AdditionalDetailsTemplate">
<Grid>
<DockPanel>
<TextBlock HorizontalAlignment="Left" Margin="0,0,0,10" Text="{Binding Path=.}" TextWrapping="Wrap" />
</DockPanel>
</Grid>
</DataTemplate>
</Grid.Resources>
<ListView FontWeight="Normal"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
HorizontalContentAlignment="Stretch"
BorderThickness="0"
HorizontalAlignment="Left"
Margin="0"
Width="{Binding ActualWidth, ElementName=WidthSetter}" ItemTemplate="{StaticResource AdditionalDetailsTemplate}" ItemsSource="{Binding Path=AdditionalDetails}" />
<Grid Grid.Row="1" Margin="3,5,5,5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold" Text="Records involved:" />
<ListView BorderThickness="0" ItemsSource="{Binding InvolvedRecords}" ItemTemplate="{StaticResource ValidatorInvolvedRecordsTemplate}" Grid.Row="1" />
</Grid>
</Grid>
</GroupBox>
</DataTemplate>
</my:DataGrid.RowDetailsTemplate>
</my:DataGrid>
</Grid>
</DataTemplate>
</my:DataGrid.RowDetailsTemplate>
</my:DataGrid>
我认为有某种方法可以告诉子 DataGrid 将滚动事件传递到“testList”DataGrid,但我无法弄清楚如何实现。
谢谢!
I have a DataGrid "nested" inside another DataGrid's RowDetailsTemplate. Scrolling works fine whenever my mouse is over the main portion of the row on the parent DataGrid, but when the mouse is over the DataGrid nested inside the RowDetailsTemplate, it stops scrolling.
Here is the DataGrid setup:
<my:DataGrid Margin="-2,36,-2,1"
Background="White"
CanUserReorderColumns="True"
CanUserResizeRows="False"
ColumnHeaderHeight="35"
HorizontalGridLinesBrush="LightGray"
VerticalGridLinesBrush="White"
x:Name="testList"
VerticalScrollBarVisibility="Visible"
FlowDirection="LeftToRight"
AutoGenerateColumns="False"
IsReadOnly="True"
ScrollViewer.CanContentScroll="False"
SelectionMode="Single"
HeadersVisibility="Column"
GridLinesVisibility="None"
>
<my:DataGrid.Columns>
<my:DataGridTemplateColumn MinWidth="60" CanUserSort="True" SortMemberPath="ResultType">
<my:DataGridTemplateColumn.Header>
<TextBlock FontSize="14" Text="Result"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="4" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Height="35" Width="35" Source="{Binding TestResultImage}" ToolTip="{Binding ResultType}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="100" CanUserSort="True" SortMemberPath="TestName">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="3" FontSize="14" Text="Dates"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock FontSize="14" TextWrapping="Wrap" AllowDrop="True" Text="{Binding TestName}" ToolTip="This test analyzed data from this date" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="150" Width="*" CanUserSort="True" x:Name="TestDetails" SortMemberPath="Result">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="4" FontSize="14" Text="Details"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5" VerticalAlignment="Center">
<TextBlock TextWrapping="Wrap" FontSize="13" Text="{Binding Result}" ToolTip="Click for more details about this test" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
<my:DataGrid.RowDetailsTemplate>
<DataTemplate>
<Grid>
<my:DataGrid Background="White"
BorderThickness="0"
CanUserReorderColumns="True"
HeadersVisibility="Column"
CanUserResizeRows="False"
ColumnHeaderHeight="25"
ItemsSource="{Binding GuiValidatorResults}"
HorizontalGridLinesBrush="LightGray"
x:Name="validatorList"
VerticalGridLinesBrush="White"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
FlowDirection="LeftToRight"
AutoGenerateColumns="False"
IsReadOnly="True"
ScrollViewer.CanContentScroll="False"
ScrollViewer.ScrollChanged=""
SelectionMode="Single"
MouseDoubleClick="HideAllValidatorDetails"
GridLinesVisibility="Horizontal">
<my:DataGrid.Columns>
<my:DataGridTemplateColumn MinWidth="60" CanUserSort="True" SortMemberPath="ResultType">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="0" Text="Result"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="0">
<Image Height="25" Width="25" Source="{Binding ValidatorResultImage}" ToolTip="{Binding ResultType}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="100" CanUserSort="True" SortMemberPath="DescriptiveTestLabel">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="0" Text="Validator"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5">
<TextBlock TextWrapping="Wrap" AllowDrop="True" Text="{Binding DescriptiveTestLabel}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn MinWidth="150" Width="*" CanUserSort="True" SortMemberPath="Text">
<my:DataGridTemplateColumn.Header>
<TextBlock Margin="0" Text="Message"></TextBlock>
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5">
<TextBlock TextWrapping="Wrap" AllowDrop="True" Text="{Binding Text}" />
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
<my:DataGrid.RowDetailsTemplate>
<DataTemplate>
<GroupBox FontWeight="Bold" Margin="5" Header="Additional Details:">
<Grid Margin="5" x:Name="WidthSetter">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Resources>
<DataTemplate x:Key="AdditionalDetailsTemplate">
<Grid>
<DockPanel>
<TextBlock HorizontalAlignment="Left" Margin="0,0,0,10" Text="{Binding Path=.}" TextWrapping="Wrap" />
</DockPanel>
</Grid>
</DataTemplate>
</Grid.Resources>
<ListView FontWeight="Normal"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
HorizontalContentAlignment="Stretch"
BorderThickness="0"
HorizontalAlignment="Left"
Margin="0"
Width="{Binding ActualWidth, ElementName=WidthSetter}" ItemTemplate="{StaticResource AdditionalDetailsTemplate}" ItemsSource="{Binding Path=AdditionalDetails}" />
<Grid Grid.Row="1" Margin="3,5,5,5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold" Text="Records involved:" />
<ListView BorderThickness="0" ItemsSource="{Binding InvolvedRecords}" ItemTemplate="{StaticResource ValidatorInvolvedRecordsTemplate}" Grid.Row="1" />
</Grid>
</Grid>
</GroupBox>
</DataTemplate>
</my:DataGrid.RowDetailsTemplate>
</my:DataGrid>
</Grid>
</DataTemplate>
</my:DataGrid.RowDetailsTemplate>
</my:DataGrid>
I would think that there would be some way to tell the child DataGrid to pass the scroll event up to the "testList" DataGrid, but I haven't been able to figure out how.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非 RowDetails 本身正在处理滚动,否则请尝试将主 DataGrid 上的属性 ScrollViewer.CanContentScroll 设置为 false。
Unless the RowDetails is handling the scrolling itself, try setting the property ScrollViewer.CanContentScroll on the main DataGrid to false.
我在其他地方找到了此问题的解决方案:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e7c3a3b0-3b89-40a3-9160-a930724251fe/nested-datagrid-scrolling-woes ?forum=wpf
基本上是说在 CodeBehind 中使用此方法:
并且在 xaml 中,嵌套的 DataGrid 开始标记包含:
I found a solution to this problem elsewhere:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e7c3a3b0-3b89-40a3-9160-a930724251fe/nested-datagrid-scrolling-woes?forum=wpf
Which basically says use this method in the CodeBehind:
And in the xaml the nested DataGrid opening tags contain: