编辑
我相信这是 DataGrid 实现中的一个错误。如果它真的对待你,我建议你滚动列开始以避免这种不需要的行为。
恕我直言,问题本身在System.Windows.Controls.DataGridColumnFloatingHeader
. 由于这个类是内部的,所以很难解决这个问题。
如何重现:
向右滚动一点,而不是拖动第一列。
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="400" Width="300">
<ScrollViewer x:Name="uiScroll">
<DataGrid Grid.Row="3" x:Name="uiGrid">
<DataGrid.Columns>
<DataGridTextColumn Width="200" Header="Test 1" Binding="{Binding Key}" />
<DataGridTextColumn Width="200" Header="Test 2" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
</Window>
...
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
uiGrid.ItemsSource = new Dictionary<string, string>() { { "key1", "val1" }, { "key2", "val2" } };
}
}