Click here to Skip to main content
14,641,690 members
Rate this:
Please Sign up or sign in to vote.
See more:
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"








        d:DesignHeight="414" d:DesignWidth="660" >
        <DataGrid AutoGenerateColumns="False" Height="250" HorizontalAlignment="Left" Margin="93,58,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="469" >
                            <CheckBox Content="Type" x:Name="chkHeader" IsChecked="{Binding ElementName=WindowDisplay, Path=IsHeaderSelected, Mode=TwoWay}"  IsThreeState="True" />
                            <CheckBox IsChecked="{Binding ElementName=WindowDisplay, Path=IsHeaderSelected, Mode=TwoWay}" Content="{Binding Name}" />

Code Behind
namespace WPF_TEST
    /// <summary>
    /// Interaction logic for MainDisplayWindow.xaml
    /// </summary>
    public partial class MainDisplayWindow : Window

        public bool? IsHeaderSelected
            get { return (bool?)GetValue(IsHeaderSelectedProperty); }
            set { SetValue(IsHeaderSelectedProperty, value); }
        // Using a DependencyProperty as the backing store for IsHeaderSelected.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsHeaderSelectedProperty =
            DependencyProperty.Register("IsHeaderSelected", typeof(bool?), typeof(MainDisplayWindow), new UIPropertyMetadata(null));
        public MainDisplayWindow()
            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.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I found this link in stackoverflow which might be useful for you.

[no name] 6-Aug-12 10:15am
hi thanks for reply. but i don't want to use the code behind to handle that checkbox event. is there is any way that we can handle it in the XAML itself?
Aditya Mangipudi 6-Aug-12 10:20am
So you would like to show it on the page. Something like this
[no name] 11-Aug-12 1:36am
Ya some thinglike that but i have to try it on grid any way thanks. and sorry for the delay little busy.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100