【发布时间】:2015-02-16 10:00:11
【问题描述】:
这是我的 Employee 类。
public class Employee
{
public string LastName { get; set; }
public string FirstName { get; set; }
public bool Fire { get; set; }
}
这就是 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">
<Grid Loaded="EmployeesGridLoaded">
<DataGrid x:Name="gEmployees" HorizontalAlignment="Left" Margin="10,10,0,0"
VerticalAlignment="Top" AlternatingRowBackground="LightBlue" AlternationCount="2" AutoGenerateColumns="False" Grid.Row="0">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Fire" Binding="{Binding Fire}" Width="1*" />
<DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" Width="3*" />
<DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" Width="3*" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
最后是EmployeesGridLoaded方法。
private void EmployeesGridLoaded(object sender, RoutedEventArgs e)
{
List<Employee> Employees = new List<Employee>()
{
new Employee() { Fire = false, LastName = "Silly", FirstName = "Dude" },
new Employee() { Fire = false, LastName = "Mean", FirstName = "Person" },
};
gEmployees.ItemsSource = Employees;
}
}
问题是当我第一次单击 Fire 复选框时,它并没有立即将其状态更改为选中。我必须再单击一次才能将其状态更改为检查。它可能是第一次选择行。当我单击此单元格并且尚未在网格中选择行时,是否有第一次检查它?
【问题讨论】: