TriState and Binding

5 posts, 1 answers
  1. Adam Marshall
    Adam Marshall avatar
    46 posts
    Member since:
    Nov 2009

    Posted 17 Feb 2010 Link to this post

    Hi,

    I am binding a treeview to a collection of objects. This is for use in a user/group permissions for my application.
    The treeview is displaying up to four levels

    The tree binds to a property on the object of type bool? , to achieve the tri state. 

    This is the ItemContainerStyle for the treeview
     <Style x:Key="GroupSecurityRadTreeStyle" TargetType="telerik:RadTreeViewItem">  
        <Setter Property="CheckState" Value="{Binding IsGroupActivated,Mode=TwoWay, Converter={StaticResource CheckStateConverter}}"/>  
        <Setter Property="IsExpanded" Value="True"/>          
     </Style> 

    The value converter;
       public class CheckStateConverter : IValueConverter  
        {  
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
            {              
                bool? result = (bool?)value;  
                if (result.HasValue)  
                {  
                    return result.Value ? ToggleState.On : ToggleState.Off;  
                }  
                else 
                {  
                    ToggleState o = ToggleState.Indeterminate;  
                    return o;  
                }  
            }  
     
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
            {  
                ToggleState state = (ToggleState)value;  
                return state == ToggleState.On ? true : false;  
            }  
        } 

    The binding to the tree works perfectly, the problem I am having is when an treeviewitem is in the indeterminate state on the tree view.

    When an item has been put in the indeteminate state, the (ToggleState)value in the ConvertBack method is set to 'Off', I would have expected this to be set to 'Indeterminate'.

    I know the ConvertBack method doesn't actually deal with the indeterminate state, but that is due to me not being able to get it.

    Is there something I am doing wrong?

    Thanks,

    A Marshall
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Feb 2010 Link to this post

    Hi Adam Marshall,

    Can you please try to modify the ConvertBack method like this:

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                ToggleState state = (ToggleState)value;
                if (state == ToggleState.Indeterminate)
                    return null;
                else return state == ToggleState.On ? true : false;
            }

    Please let us know if this helps or you need any additional info.

    Regards,
    Tina Stancheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Adam Marshall
    Adam Marshall avatar
    46 posts
    Member since:
    Nov 2009

    Posted 22 Feb 2010 Link to this post

    Hi,

    Thanks for the reply.

    The issue is the fact that within the ConvertBack method, the value of  "ToggleState state = (ToggleState)value;" is never Indeterminate.

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
            {  
                ToggleState state = (ToggleState)value;  
                if (state == ToggleState.Indeterminate)  
                    return null;  
                else return state == ToggleState.On ? true : false;  
            } 

    So null is never actually returned.

    Is it possible for you to confirm that the (ToggleState)value actually has an Indeterminate value, as this is the problem I am having.

    I understand that your above ConvertBack method should work and it is exactly what I am trying to achieve, but it doesn't appear to work.

    Thank you,

    A Marshall
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 25 Feb 2010 Link to this post

    Hello Adam Marshall,

    There appears to be a bug when the CheckState property is databound. I will test whether this Indeterminate case is indeed affected and I will follow up here.

    Greetings,
    Miroslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 26 Feb 2010 Link to this post

    Hello Adam Marshall,

    The fixes for the TriState binding just missed this week's internal build.

    I checked that the binding is updated with Intermediate state as well.

    The project I used is attached to my reply.

    Kind regards,
    Miroslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for WPF is Visual Studio 2017 Ready