Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4550212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:27:58+00:00 2026-05-21T16:27:58+00:00

I have a datagrid where the first column contains a checkbox to let the

  • 0

I have a datagrid where the first column contains a checkbox to let the user selects specific rows. I have added a checkbox in the datagrid column header to check or uncheck all the rows.

Is it possible to add this functionality only with binding in XAML (no checked event).

<sdk:DataGrid AutoGenerateColumns="False" Grid.Row="1"  Name="grid" ItemsSource="{Binding myCollection, Mode=TwoWay}" >
        <sdk:DataGrid.Columns>
            <sdk:DataGridCheckBoxColumn Binding="{Binding myCollection.UserSelected, Mode=TwoWay}" >
                <sdk:DataGridCheckBoxColumn.HeaderStyle>
                    <Style TargetType="sdk:DataGridColumnHeader">
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <CheckBox x:Name="checkAll" IsThreeState="True"  
                                              IsChecked="{Binding myCollection.UserSelected, Mode=TwoWay, Converter={StaticResource threeStateConverter}}"/>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </sdk:DataGridCheckBoxColumn.HeaderStyle>
            </sdk:DataGridCheckBoxColumn>
            <sdk:DataGridTextColumn Binding="{Binding Description}" Header="Chemin" />
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>

I think there’s something wrong with the “myCollection.UserSelected” part. ThreeStateConverter is a value converter that would return null when some items are selected, true when they are all selected, etc. but the Convert method is never called (even though the PropertyChanged event is raised when UserSelected is changed).

Any idea on how I can do it? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:27:58+00:00Added an answer on May 21, 2026 at 4:27 pm

    Probably, you’ve solved the problem already, but nevertheless:

    <navigation:Page.Resources>
        <model:MyModel x:Key="Model"/>
    </navigation:Page.Resources>
    ...    
    <data:DataGridTemplateColumn Width="Auto" >
        <data:DataGridTemplateColumn.HeaderStyle>
            <Style TargetType="datap:DataGridColumnHeader">
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <CheckBox IsThreeState="True" Margin="2,0,-13,0" DataContext="{StaticResource Model}" IsChecked="{Binding Path=AllChecked, Mode=TwoWay}"/>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </data:DataGridTemplateColumn.HeaderStyle>
        <data:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <CheckBox IsChecked="{Binding Checked, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </DataTemplate>
        </data:DataGridTemplateColumn.CellTemplate>
    </data:DataGridTemplateColumn>
    

    MyModel class contains bool? property that implements logic of selection. It is also used as a `DataContext of page.

    I must admit that this potentially has problems if we need to change model.

    EDIT: I found another way:

    <navigation:Page.DataContext>
        <model:MyModel />
    </navigation:Page.DataContext>
    ...    
    <data:DataGridTemplateColumn Width="Auto" >
        <data:DataGridTemplateColumn.HeaderStyle>
            <Style TargetType="datap:DataGridColumnHeader">
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <CheckBox IsThreeState="True" Margin="2,0,-13,0" IsChecked="{Binding Path=DataContext.AllChecked, ElementName=LayoutRoot, Mode=TwoWay}"/>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </data:DataGridTemplateColumn.HeaderStyle>
        <data:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <CheckBox IsChecked="{Binding Checked, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </DataTemplate>
        </data:DataGridTemplateColumn.CellTemplate>
    </data:DataGridTemplateColumn>
    

    Here we bind to DataContext of root layout element (usually called LayoutRoot) which inherits its data context from page by default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flex datagrid with 3 columns. The first column contains the image
I have a datagrid called DataGridView1, column A contains a name, column B contains
I have a user control that contains a WPF toolkit DataGrid . This control
I have a datagrid with 2 columns. One column contains role information, the other
I have two datagrids with one column each. First: <DataGrid.Columns> <DataGridTextColumn x:Name=FilterTextCol01 IsReadOnly=False Width={Binding
How can I make my datagrid have its first column fixed and scroll the
I have a DataGrid and I would like to have my first column's cells
I have a WPF DataGrid that in its first column holds a number that
I have button at first column in datagrid. I am using MVVM and try
I have to designed a datagrid, in first column i have to use closed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.