我打算继续关注 DataGrid 的选定行。为此,我搜索并找到链接如何将数据网格上的焦点设置到特定行?..当我在我的项目中尝试相同的操作时,我发现该行总是返回 null ..
我也为此进行了检查并获得了链接...在这里我没有使用虚拟化,而且我已经关闭了虚拟化..仍然面临同样的问题..我可以知道为什么返回null的一些原因吗?
<DataGrid Name="DGrid"
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Stretch"
AutoGenerateColumns="False"
BorderThickness="0"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserResizeColumns="False"
CanUserSortColumns="True"
HeadersVisibility="Column"
IsReadOnly="True"
ItemsSource="{Binding Path=Reports,
NotifyOnSourceUpdated=True}"
MouseDoubleClick="DGrid_MouseDoubleClick"
PreviewKeyDown="DGrid_PreviewKeyDown"
SelectionChanged="DGrid_SelectionChanged"
SelectionMode="Extended"
SelectionUnit="FullRow"
VerticalScrollBarVisibility="Auto" VirtualizingStackPanel.IsVirtualizing="False">
<DataGrid.Resources>
<Style x:Key="CellEditingStyle" TargetType="DataGridCell">
<Setter Property="DataGridCell.IsTabStop" Value="False" />
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn x:Name="DueStatus"
Width="16"
CellStyle="{StaticResource CellEditingStyle}"
SortMemberPath="OverDue">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!-- ReSharper disable Xaml.BindingWithContextNotResolved - This will be generated at Runtime -->
<Image Name="ImgOvr"
Width="16"
Height="16"
Source="/VersadexMreUs;component/Images/signal_flag_red.png"
Visibility="{Binding Converter={StaticResource TextToVisiblity},
Path=OverDue}" />
<!-- ReSharper restore Xaml.BindingWithContextNotResolved -->
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn x:Name="ArrestStatus"
Width="16"
CellStyle="{StaticResource CellEditingStyle}"
SortMemberPath="ArrestMade">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!-- ReSharper disable Xaml.BindingWithContextNotResolved - This will be generated at Runtime -->
<Image Width="16"
Height="16"
Source="/VersadexMreUs;component/Images/car_compact_red.png"
Visibility="{Binding Converter={StaticResource TextToVisiblity},
Path=ArrestMade}" />
<!-- ReSharper restore Xaml.BindingWithContextNotResolved -->
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn x:Name="IncompleteStatus"
Width="16"
CellStyle="{StaticResource CellEditingStyle}"
SortMemberPath="InComplete">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!-- ReSharper disable Xaml.BindingWithContextNotResolved - This will be generated at Runtime -->
<Image Width="16"
Height="16"
Source="/VersadexMreUs;component/Images/document_warning.png"
Visibility="{Binding Converter={StaticResource TextToVisiblity},
Path=InComplete}" />
<!-- ReSharper restore Xaml.BindingWithContextNotResolved -->
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn x:Name="RptStatus"
MinWidth="120"
Binding="{Binding Path=StatusMessage,
Converter={StaticResource TextToUpper}}"
Header="Status" />
<DataGridTextColumn x:Name="RptDesc"
MinWidth="200"
Binding="{Binding Path=Description,
Converter={StaticResource TextToUpper}}"
Header="Report Description" />
<DataGridTextColumn x:Name="RptState"
MinWidth="250"
Binding="{Binding Path=CurrentState,
Converter={StaticResource TextToUpper}}"
Header="Current State" />
<DataGridTextColumn x:Name="RptOfficer"
MinWidth="180"
Binding="{Binding Path=OfficerName,
Converter={StaticResource TextToUpper}}"
Header="Reporting Officer" />
<DataGridTextColumn x:Name="RptDate"
MinWidth="83"
Binding="{Binding Path=SubmitDate,
Converter={StaticResource TextToUpper}}"
Header="Submit Date" />
</DataGrid.Columns>
</DataGrid>