当我选中WPF Datagrid时,它会聚焦第一个单元格(带有一个矩形)但不选择它(蓝色).如果我再次按Tab键,它会聚焦并选择它.
我认为DataGridCell实际上有IsSelected = true,但它没有被涂成蓝色.我曾尝试使用数据网格和视觉状态进行黑客攻击,但是当你第一次选中时,我无法正确地重新绘制网格.
有没有人见过这个,你有解决方案吗?
代码重现:
MainWindow.xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBox Width="100"/>
<DataGrid SelectionMode="Single" SelectionUnit="Cell"
ItemsSource="{Binding MyItems}" AutoGenerateColumns="True"/>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml.cs
using System.Collections.Generic;
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MyItems.Add(new Thingy() { Name = "Frank", Age = 34 });
MyItems.Add(new Thingy() { Name = "Jim", Age = 43 });
MyItems.Add(new Thingy() { Name = "Bob", Age = 56 });
MyItems.Add(new Thingy() { …Run Code Online (Sandbox Code Playgroud)