С этим приложением первый столбец в сетке - это тип флажка, в заголовке которого указано «Выбрать». Я бы хотел, чтобы заголовок также показывал флажок. Если флажок установлен или снят, отметьте или снимите все элементы в сетке. Как я могу это сделать?Как получить флажок в заголовке сетки
<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="350" Width="525">
<Grid Loaded="Data_Loaded" >
<Grid.RowDefinitions>
<RowDefinition Height="6*" />
<RowDefinition />
</Grid.RowDefinitions>
<DataGrid x:Name="grEmployees" HorizontalAlignment="Left" Margin="10,10,0,0" CanUserAddRows="False" CanUserDeleteRows="False"
VerticalAlignment="Top" AlternatingRowBackground="LightBlue" AlternationCount="2" AutoGenerateColumns="False" Grid.Row="0">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Select" Width="2*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="chkSelectedDevice" IsChecked="{Binding Path=Configure, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Last Name" Binding="{Binding LastName, Mode=OneWay}" Width="3*" />
<DataGridTextColumn Header="First Name" Binding="{Binding FirstName, Mode=OneWay}" Width="2*" />
<DataGridTextColumn Header="Description" Binding="{Binding Description, Mode=OneWay}" Width="5*" />
</DataGrid.Columns>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5" Grid.Row="1" >
<Button x:Name="btnClose" Content="Close" Margin="5" Width="50" />
</StackPanel>
</Grid>
</Window>
public partial class MainWindow : Window
{
private List<Employee> Employees = null;
public MainWindow()
{
InitializeComponent();
}
private void Data_Loaded(object sender, RoutedEventArgs e)
{
Employees = new List<Employee>()
{
new Employee() { IsHardWorking = false, LastName = "Silly", FirstName = "Dude", Description= "this due is a mess" },
new Employee() { IsHardWorking = true, LastName = "Mean", FirstName = "Person", Description= "funny" },
new Employee() { IsHardWorking = false, LastName = "New", FirstName = "Friend", Description= "let her go in next round of layoffs" },
new Employee() { IsHardWorking = true, LastName = "My", FirstName = "Buddy", Description= "simply no comments" },
};
this.grEmployees.ItemsSource = Employees;
}
}
Добавьте шаблон заголовка для столбца выбора, чтобы установить флажок. Установите команду для этого флажка, чтобы вы могли изменить свойство Configure для своих моделей просмотра. – bleepzter
' ' –
: ваши @ Крис примеры помогают мне решить эту проблему, но я не могу отметить комментарии как ответ. Могу только проголосовать за него :) – BKS