This is a migrated thread and some comments may be shown as answers.

Checked and uncheked raised multiple times

5 Answers 18 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Patrick asked on 10 Oct 2012, 07:28 AM
Hello,

create a new Telerik Silverlight application and replace
MainPage.xaml with:
<UserControl
  x:Class="RadControlsSilverlightApp1.MainPage"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid Margin="5">
    <Grid.ColumnDefinitions>
      <ColumnDefinition />
      <ColumnDefinition />
    </Grid.ColumnDefinitions>
 
    <telerik:RadTreeView IsLineEnabled="True"
                         IsOptionElementsEnabled="True"
                         IsTriStateMode="True"
                         ItemsOptionListType="CheckList"
                         Margin="5"
                         Checked="RadTreeView_Checked"
                         Unchecked="RadTreeView_Unchecked">
      <telerik:RadTreeViewItem Header="Group"
                               IsExpanded="True">
        <telerik:RadTreeViewItem Header="Item1" />
        <telerik:RadTreeViewItem Header="Item2" />
        <telerik:RadTreeViewItem Header="Item3" />
      </telerik:RadTreeViewItem>
    </telerik:RadTreeView>
 
    <telerik:RadListBox Name="EventList"
                        Margin="5"
                        Grid.Column="1" />
 
    </Grid>
</UserControl>

and
MainPage.xaml.cs with:
using System;
using System.Windows.Controls;
using Telerik.Windows;
 
namespace RadControlsSilverlightApp1
{
  public partial class MainPage : UserControl
  {
    public MainPage()
    {
      InitializeComponent();
    }
 
    private void RadTreeView_Checked(object sender, RadRoutedEventArgs e)
    {
      Dispatcher.BeginInvoke(
        () =>
          EventList.Items.Add(DateTime.Now.ToString() + ": Checked")
        );
    }
 
    private void RadTreeView_Unchecked(object sender, RadRoutedEventArgs e)
    {
      Dispatcher.BeginInvoke(
        () =>
          EventList.Items.Add(DateTime.Now.ToString() + ": Unchecked")
        );
    }
 
  }
}

Run the application:
  1. When you check Group, 4 Checked events are raised.
  2. Now if you uncheck Item1, one Checked and one Unchecked events are raised.
  3. Now if you uncheck Item2, one Unchecked event is raised: correct.
  4. Now if you check Item1, one Checked event is raised: correct.
  5. Now if you check Item2, two Checked events are raised.

The Checked and Unchecked events should really be raised only once in cases 1 and 5.
Case 2 is a special one, because the new state is indeterminate and there is no special event for this case.

Patrick

5 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 12 Oct 2012, 01:05 PM
Hi Patrick,

This is the expected behavior of the control. The additional events are invoked because the parent node needs to update it's status due to the TriStareMode. Please see the attached project for better understanding where the OriginalSource (the RadtreeViewItem for which is fired the event) is also written in the output.
For further information you can also read about the TriStateMode in this article.

Greetings,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 12 Oct 2012, 01:15 PM
Pavel,
the attached project is not the right one: it seems that it's a project about closable tab items.
Patrick
0
Pavel R. Pavlov
Telerik team
answered on 12 Oct 2012, 01:35 PM
Hello Patrick,

Please excuse me for the mistake I`ve made.

Here is the correct project.

Kind regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 12 Oct 2012, 01:56 PM
Pavel,
I see how I must correct my code to avoid firing my Changed event too often (I need to detect when there is any change is the selection).
One last question: what is the difference between the IsChecked and CheckState properties of RadTreeViewItem?
I've seen cases where IsChecked is false and CheckState is on?
Patrick
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 17 Oct 2012, 02:07 PM
Hello Patrick,

In brief, the RadTreeView uses the CheckState property to manage its TriStateMode while the IsChecked property is not used in tri-state value propagation as it is designed to be used with data binding. For more detailed information you can read this blog post.

Kind regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeView
Asked by
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Pavel R. Pavlov
Telerik team
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or