我在WPF中使用DataGrid来显示一些值。值刷新所有1000毫秒。
现在,如果我关注一行,并且事件刷新了所选行,则焦点将丢失。
是否有任何选项可以让焦点保持活动状态?
这是我的DataGrid:
<DataGrid x:Name="dgItems" Grid.Row="0" HorizontalAlignment="Stretch" CanUserAddRows="False" GridLinesVisibility="None" SelectionUnit="FullRow" AutoGenerateColumns="False" IsReadOnly="True" Margin="0,10,10,0" ItemsSource="{Binding}" Background="White">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="Auto" Binding="{Binding Name}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="2 0 8 0" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Wert" Width="Auto" Binding="{Binding Value}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="2 0 8 0" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Zeit" Width="Auto" Binding="{Binding DisplayTime}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="2 0 8 0" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
更新功能
private void UpdateItem(String ItemName)
{
foreach(RecItem item in dgMain.Items)
{
if(item.Name == ItemName)
{
Modify item...
....
}
}
dgMain.Items.Refresh();
}