嵌套在另一个数据网格的 RowDetailsTemplate 中的数据网格会中断鼠标滚轮滚动

发布于 2024-09-04 02:48:36 字数 12090 浏览 4 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(2

樱&纷飞 2024-09-11 02:48:36

除非 RowDetails 本身正在处理滚动,否则请尝试将主 DataGrid 上的属性 ScrollViewer.CanContentScroll 设置为 false。

ScrollViewer.CanContentScroll="False"

Unless the RowDetails is handling the scrolling itself, try setting the property ScrollViewer.CanContentScroll on the main DataGrid to false.

ScrollViewer.CanContentScroll="False"
心意如水 2024-09-11 02:48:36

我在其他地方找到了此问题的解决方案:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/e7c3a3b0-3b89-40a3-9160-a930724251fe/nested-datagrid-scrolling-woes ?forum=wpf

基本上是说在 CodeBehind 中使用此方法:

private void NestedDataGrid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
    {
        e.Handled = true;
        var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
        eventArg.RoutedEvent = UIElement.MouseWheelEvent;
        eventArg.Source = sender;
        var parent = ((Control)sender).Parent as UIElement;
        parent.RaiseEvent(eventArg);
    }

并且在 xaml 中,嵌套的 DataGrid 开始标记包含:

x:Name="NestedDataGrid" PreviewMouseWheel="NestedDataGrid_PreviewMouseWheel"

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:

private void NestedDataGrid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
    {
        e.Handled = true;
        var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
        eventArg.RoutedEvent = UIElement.MouseWheelEvent;
        eventArg.Source = sender;
        var parent = ((Control)sender).Parent as UIElement;
        parent.RaiseEvent(eventArg);
    }

And in the xaml the nested DataGrid opening tags contain:

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