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 7583943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:48:16+00:00 2026-05-30T18:48:16+00:00

I searched this topic and found several discussions. What I didn’t like about those

  • 0

I searched this topic and found several discussions.
What I didn’t like about those implementations is that they either implied special kind of the bound data (with IsSelected property) or lacked normal keyboard support.

CheckBox in a list is more a decorative thing rather than functionalyty extension thus it should be treated accordingly.

I started from this nice and helpful article: http://www.gbogea.com/2010/01/02/mvvm-multiselect-listbox

But I beleive hacking View in favor of the ViewModel is not quite good practice. It’s ViewModel to be adapted to View and Model. Surely, IMHO.

So I changed a little and finished with this XAML:

<ListBox Name="checkboxList"
                 ItemsSource="{Binding Sports}"
                 Margin="0,5"
                 SelectionMode="Multiple">
            <ListBox.ItemContainerStyle>
                <Style>
                    <Setter Property="ListBoxItem.Background" Value="Transparent"/>
                    <Setter Property="ListBoxItem.Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <Border x:Name="Bd" 
                                SnapsToDevicePixels="true" 
                                Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}">
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <CheckBox IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=IsSelected, Mode=TwoWay}" 
                              Content="{Binding}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

Here CheckBox selection is in sync with ListBoxItem.IsSelected and ListBox is unaware of the bound data peculiarities.

This is Ok.
But Is there any way to add Select|Deselect All for the ListBox by adding one more checkbox to the control template? Using only XAML.

  • 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-30T18:48:18+00:00Added an answer on May 30, 2026 at 6:48 pm

    You could do something like that using for example Interactivity from the Blend SDK

    <ListBox ItemsSource="{Binding Data}" SelectionMode="Extended">
        <ListBox.Template>
            <ControlTemplate TargetType="ListBox">
                <StackPanel>
                    <CheckBox Content="All">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Checked">
                                <is:CallMethodAction MethodName="SelectAll"
                                        TargetObject="{Binding RelativeSource={RelativeSource TemplatedParent}}" />
                            </i:EventTrigger>
                            <i:EventTrigger EventName="Unchecked">
                                <is:CallMethodAction MethodName="UnselectAll"
                                        TargetObject="{Binding RelativeSource={RelativeSource TemplatedParent}}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </CheckBox>
                    <ItemsPresenter />
                </StackPanel>
            </ControlTemplate>  
        </ListBox.Template>
    </ListBox>
    

    This however does not solve a problem you did not mention or think of, namely that the state of that CheckBox will not change when the selection is changed without using it. You could instead bind the IsChecked state using a MultiBinding and value converter to get it into the right state, you then could also drop the events. It is also rather messy though.

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

Sidebar

Related Questions

I searched for this and found Maudite's question about text editors but they were
I searched and found this question but did not like the answer. Is there
I've searched over this topic but found very few details which were helpful. With
I have searched a lot about this topic and I can't get this code
I've searched (google and SO) about this topic and couldn't find a thorough answer
Ok, so I've searched stackoverflow and found unanswered sub-topics regarding this issue, that's why
I have searched and found some info on this topic but the answers are
I searched for a while on this topic and found some results too, which
I've searched a bit on this topic and found a few results. However, I'm
I've searched and found a number of StackOverflow Q/A's regarding this topic, but I

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.