I started with the example with the Leages and Division (as example for data binding from the Demo) and added a tristate checkbox to the treeview and a "bool?" in each class. Initially all items are set to "true".
As described here I added the CheckStateConverter class which also handles the Indeterminate state.
The data binding works fine, but the thing I can't understand: If I expand "League A" and "Division A" and uncheck "Team I", "League A" and "Division A" also switch to "unchecked" instead of "indeterminate". If I uncheck "League A" and check it again the whole tree behaves correctly. What is wrong in my example?
Thanks in advance!
Jan
public League(string name) |
{ |
_name = name; |
_divisions = new List<Division>(); |
_selected = true; |
} |
string _name; |
bool? _selected; |
public string Name { get { return _name; } } |
public bool? Selected { get { return _selected; } } |
As described here I added the CheckStateConverter class which also handles the Indeterminate state.
public class CheckStateConverter : IValueConverter |
{ |
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
{ |
bool? result = (bool?)value; |
ToggleState returnValue = ToggleState.Indeterminate; |
if (result == true) |
returnValue = ToggleState.On; |
else |
{ |
if (result == false) |
returnValue = ToggleState.Off; |
} |
return returnValue; |
} |
//.... |
The data binding works fine, but the thing I can't understand: If I expand "League A" and "Division A" and uncheck "Team I", "League A" and "Division A" also switch to "unchecked" instead of "indeterminate". If I uncheck "League A" and check it again the whole tree behaves correctly. What is wrong in my example?
Thanks in advance!
Jan