我的 DataGrid 出现在可视范围之外的数据。我在 StackOverflow 上查看了几个类似的问题,但似乎都没有解决我的问题。我无法弄清楚我做错了什么。这就是我的 xaml 的样子:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" Foreground="{DynamicResource TitleFontColor}"
TextWrapping="Wrap" Text="{Binding WindowTitle}" VerticalAlignment="Center"
Margin="10,10,0,10" FontSize="18.667" FontFamily="Segoe UI" />
<Border Background="{DynamicResource pnlworkarea}"
Grid.Row="1" CornerRadius="2" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="65"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderThickness="1"
Background="{DynamicResource Brush_HeaderNew}"
BorderBrush="{DynamicResource pnlworkareastroke}"
CornerRadius="2" Margin="5">
<Grid Margin="0">
<ListBox ItemsSource="{Binding ViewMenuItems}" SelectedItem="{Binding Viewselected}"
VerticalAlignment="Center" Style="{DynamicResource Content_Header_ListBoxStyle}"
ItemTemplate="{DynamicResource Header_DataTemplate}"
ItemContainerStyle="{DynamicResource ContentHeader_ListBoxItemStyle}"
ItemsPanel="{DynamicResource Header_ItemsPanelTemplate}" HorizontalAlignment="Left"/>
</Grid>
</Border>
<Grid Grid.Row="1" Margin="5">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top" Margin="10,0,0,0">
<ContentControl Focusable="False" Content="ContentControl"
Background="{DynamicResource Brush_VectorIcon}"
Template="{DynamicResource vector_Summary}"
Height="16" Margin="0,5,0,0"/>
<TextBlock TextWrapping="Wrap" Text="{Binding SearchDisplayMessage}" Margin="5,3,0,0" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
<Grid Grid.Row="2" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="dataGrid"
commands:ControlEvents.GridViewSelectionChangedEventCommand="{Binding SelectionItemsChangeCommand}"
SelectionMode="Single"
AutoGenerateColumns="True"
Margin="0,5" Grid.Row="1" IsReadOnly="True"
ItemsSource="{Binding GridItem, Mode=TwoWay}" SelectedItem="{Binding SelectedItem}"
AlternatingRowBackground="#FFF5F4F8" Background="White" Grid.ColumnSpan="2"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<i:Interaction.Behaviors>
<Behaviors:SelectorDoubleClickCommandBehavior Command="{Binding GridDoubleclickcommand}"/>
</i:Interaction.Behaviors>
</DataGrid>
</Grid>
</Grid>
</Border>
</Grid>
只是要补充一点,这里的 DataGrid 不是我正在使用的实际 DataGrid。我的自定义 DataGrid 是从 DataGrid 派生的。但我也用普通的 DataGrid 试过这个,但似乎也不起作用。