Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2092
CheckBox Binding
posted

I searched the forum for this and found and "old" thread about the issue but I didn't have luck with those tips provided in the thread.

I have a scenario where I have "hard-coded" root level node (Select all). Then I bind my ObservableCollection to that item's ItemsSource. Here's the XAML of my scenario.

 

<ig:XamTree CheckBoxVisibility="Visible" CheckBoxMode="Auto">
<ig:XamTreeItem Header="Select/Deselect all" ItemsSource="{Binding MyObjects}">
<ig:XamTreeItem.ItemTemplate>
<DataTemplate>
<ig:XamTreeItem IsChecked="{Binding IsSelected, Mode=TwoWay}" Header="{Binding Name}"/>
</DataTemplate>
</ig:XamTreeItem.ItemTemplate>
</ig:XamTreeItem>
</ig:XamTree>

This doesn't work. The CheckBox doesn't update the property as expected. I got this idea by combining few samples from these forums. The basic idea came from this example:

 

<ig:XamTree CheckBoxVisibility="Visible" CheckBoxMode="Auto">
<ig:XamTreeItem Header="Select/Deselect all" ItemsSource="{Binding MyObjects}">
<ig:XamTreeItem.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ig:XamTreeItem.ItemTemplate>
</ig:XamTreeItem>
</ig:XamTree>

This looks better so basicly I need this but added with the possibility to bind the CheckBox to a boolean property of MyObject. I'm using 10.2.20102.2066 version of your control.

Any ideas how to achieve this?

 

 

  • 2092
    Verified Answer
    posted

    I got it working after some struggling. I needed to define both DefaultItemsContainer- and ItemTemplate -templates like this:

    <ig:XamTree CheckBoxVisibility="Visible" CheckBoxMode="Auto" >
    <ig:XamTreeItem Header="Select/Deselect all" ItemsSource="{Binding MyObjects}">
    <ig:XamTreeItem.DefaultItemsContainer>
    <DataTemplate>
    <ig:XamTreeItem IsChecked="{Binding IsSelected, Mode=TwoWay}" />
    </DataTemplate>
    </ig:XamTreeItem.DefaultItemsContainer>
    <ig:XamTreeItem.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding Name}" />
    </DataTemplate>
    </ig:XamTreeItem.ItemTemplate>
    </ig:XamTreeItem>
    </ig:XamTree>

    This seem to work fine. Hope this solution helps someone else too.