Hi all,
I have a CheckBox as a WPF Datagrid HeaderTemplate in my application. my application is basically a Email Inbox Application in that i need to handle ThreeState of CheckBox.
1. if IsChecked i need to select some items in the Datagrid (say UnReaded)
2. If UnChecked i need to select some items in the Datagrid (say Readed)
3. if ThreeState i need to select some items in the Datagrid (say Junk)
this is my Demo project code
Xaml Code
<Window x:Class="WPF_TEST.MainDisplayWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF_TEST"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="WindowDisplay"
d:DesignHeight="414" d:DesignWidth="660" >
<Grid>
<DataGrid AutoGenerateColumns="False" Height="250" HorizontalAlignment="Left" Margin="93,58,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="469" >
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Content="Type" x:Name="chkHeader" IsChecked="{Binding ElementName=WindowDisplay, Path=IsHeaderSelected, Mode=TwoWay}" IsThreeState="True" />
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding ElementName=WindowDisplay, Path=IsHeaderSelected, Mode=TwoWay}" Content="{Binding Name}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
Code Behind
namespace WPF_TEST
{
public partial class MainDisplayWindow : Window
{
public bool? IsHeaderSelected
{
get { return (bool?)GetValue(IsHeaderSelectedProperty); }
set { SetValue(IsHeaderSelectedProperty, value); }
}
public static readonly DependencyProperty IsHeaderSelectedProperty =
DependencyProperty.Register("IsHeaderSelected", typeof(bool?), typeof(MainDisplayWindow), new UIPropertyMetadata(null));
public MainDisplayWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainDisplayWindow_Loaded);
}
void MainDisplayWindow_Loaded(object sender, RoutedEventArgs e)
{
MyClassData res = new MyClassData();
dataGrid1.ItemsSource = res;
}
}
public class MyClass : List<MyClass>
{
public string Name { get; set; }
public MyClass()
{
}
}
public class MyClassData : List<MyClass>
{
public MyClassData()
{
this.Add(new MyClass { Name = "Readed" });
this.Add(new MyClass { Name = "UnReaded" });
this.Add(new MyClass { Name = "Junk" });
}
}
}
any one have any Idea.