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

TriState and Binding

4 Answers 131 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Adam Marshall
Top achievements
Rank 1
Adam Marshall asked on 18 Feb 2010, 03:17 AM
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

4 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 22 Feb 2010, 09:10 AM
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.
0
Adam Marshall
Top achievements
Rank 1
answered on 23 Feb 2010, 12:13 AM
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
0
Miroslav
Telerik team
answered on 25 Feb 2010, 12:39 PM
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.
0
Accepted
Miroslav
Telerik team
answered on 26 Feb 2010, 08:24 PM
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.
Tags
TreeView
Asked by
Adam Marshall
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Adam Marshall
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or