我有一个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,但是我还没弄清楚如何。
谢谢!
答案 0 :(得分:2)
除非RowDetails正在处理滚动本身,否则尝试将主DataGrid上的属性ScrollViewer.CanContentScroll设置为false。
ScrollViewer.CanContentScroll="False"
答案 1 :(得分:0)
我在其他地方找到了解决这个问题的方法:
基本上说在CodeBehind中使用此方法:
{
"data": [
{
"text": "red",
"created_time": "2017-12-05",
"comment_count": 31,
"like_count": 43,
"id": "10155952999xxxxx"
},
{
"text": "yellow",
"created_time": "2017-09-09",
"comment_count": 4,
"like_count": 876,
"id": "10155952999xxxxxx"
},
{
"text": "blue",
"created_time": "2017-05-01",
"comment_count": 15,
"like_count": 6,
"id": "10155952999xxxxxx"
}
]
}
在xaml中,嵌套的DataGrid开始标记包含:
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);
}