DataGrid的选中项在点击DataGrid之外的地方时,失去选中状态变灰。如何实现,在点击DataGrid之外地方时,选中项仍是选中的高亮状态?
<DataGrid ItemsSource="{Binding ItemsSource}" Style="{StaticResource DataGridStyle}" SelectedItem="{Binding SelectedItem}" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" RowStyle="{StaticResource CapResultStyle}" > <i:Interaction.Triggers> <i:EventTrigger EventName="MouseDoubleClick"> <i:InvokeCommandAction Command="{Binding DataContext.QueryCmd, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/> </i:EventTrigger>
</i:Interaction.Triggers> <DataGrid.Columns> <DataGridTextColumn Header="序号" Width="60" Binding="{Binding Disp}" ElementStyle="{StaticResource DataGridContentCenterSytle}" /> <DataGridTextColumn Header="时间" Width="160" Binding="{Binding DateTime}" ElementStyle="{StaticResource DataGridContentCenterSytle}" /> <DataGridTextColumn Header="处理结果" Width="80"
Binding="{Binding ResultStr}"
ElementStyle="{StaticResource DataGridContentCenterSytle}"/> </DataGrid.Columns>
</DataGrid>
修改ControlTemplate的trigger试试
最终通过,在抽象Model中增加选中项标识的方式来记录被选中的项,在Style中更具该项来显示选中颜色。