CheckedItems doesn't fire CollectionChanged event to update bound objects?

2 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 19 Jan 2011 Link to this post

    Hello,

    I am attempting to element bind a TextBox.Text property to the RadTreeView.CheckedItems collection like the sample below.  I have added a converter just so that I can see if the CheckedItems collection is actually changing but it doesn't appear to be.  Have I done something incorrectly?  The converter never fires after the initial load even though I am checking items.

    I noticed a statement in the online documentation (here) "Raised when the CheckedItems change. Currently it is only raised with 'Reset' since the set of items in unordered."  Is this part of the problem?  I would expect that anytime any item is checked/unchecked the event would be raised.

    <UserControl
        x:Class="SilverlightApplication152.MainPage"
        xmlns:local="clr-namespace:SilverlightApplication152"
        Width="500">
      
        <UserControl.Resources>
            <local:MyConverter x:Key="MyConverter" />
        </UserControl.Resources>
      
      
        <Grid>
      
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition Height="1*" />
            </Grid.RowDefinitions>
      
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
      
            <TextBox Text="{Binding ElementName=RadTreeView1, Path=CheckedItems, Converter={StaticResource MyConverter}}" />
      
            <telerik:RadDropDownButton Grid.Row="1" Grid.Column="0">
      
                <telerik:RadDropDownButton.DropDownContent>
                    <telerik:RadTreeView x:Name="RadTreeView1" IsLineEnabled="True" BorderThickness="0" SelectionMode="Multiple" IsEditable="False" IsOptionElementsEnabled="True" IsTriStateMode="False" ItemsOptionListType="CheckList">
                        <telerik:RadTreeViewItem Header="1" IsExpanded="True">
                            <telerik:RadTreeViewItem Header="aaa" />
                            <telerik:RadTreeViewItem Header="bbb" />
                            <telerik:RadTreeViewItem Header="ccc" />
                            <telerik:RadTreeViewItem Header="ddd" />
                        </telerik:RadTreeViewItem>
                        <telerik:RadTreeViewItem Header="2" IsExpanded="True">
                            <telerik:RadTreeViewItem Header="aaa" />
                            <telerik:RadTreeViewItem Header="bbb" IsExpanded="True">
                                <telerik:RadTreeViewItem Header="b1" />
                                <telerik:RadTreeViewItem Header="b2" />
                                <telerik:RadTreeViewItem Header="b3" />
                                <telerik:RadTreeViewItem Header="b4" />
                            </telerik:RadTreeViewItem>
                            <telerik:RadTreeViewItem Header="ccc" />
                            <telerik:RadTreeViewItem Header="ddd" />
                        </telerik:RadTreeViewItem>
                    </telerik:RadTreeView>
                </telerik:RadDropDownButton.DropDownContent>
      
            </telerik:RadDropDownButton>
      
        </Grid>
      
    </UserControl>

    public class MyConverter : IValueConverter
        {
            #region IValueConverter Members
      
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return "a";
            }
          
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
      
            #endregion
      
        }
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Jan 2011 Link to this post

    Hello Rob,

    Yes, the problem is the one you have mentioned: CollectionChaged of the ChekedItems is raised only Initially. I prepared a sample to workaround this with a ViewModel that uses the Checked event of the RadTreeView. Please give it a try and let me know if it satisfies you or not.

    All the best,
    Petar Mladenov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
Back to Top