4 Answers, 1 is accepted
I prepared a sample for you that meets your requirement in DataBinding scenario. I bind the FontWeight property of the TextBlock from the ItemTemplate to a CheckedState property of the ViewModel. The CheckState of the RadTreeViewItems is bound to the CheckedState via ContainerBindings. Please note that you need the child items expanded before checking their parent. Do not hesitate to ask if you need further assistance.
Regards,Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Thanks for your response, I think some files are missing from the zip. Could not find the "TreeView.csproj" file. Can you please zip again and send to me?
Thanks
Edit:
Please ignore this. I am able to see the files.
Hi Petar,
That was excellent. Thanks for the code snippet.
I have few more conditions to add this scenario.
- According to the business requirement I have IsTriStateMode = “false”
- Like I asked initially I would like to have the ancestors of the checked item also shown as bold.
- I would like to do this change (bold/normal)in view (either in .xaml or .cs file)
- I have ViewModel defined in the following way, which makes changes to the property of an object does not reflect back to UI. In other words unless I refresh the entire Hierarchy object the changes inside this object does not take effect to UI.
Model
public class Hierarchy
{
public string Name { get; set; }
public Guid Id { get; set; }
public Guid ParentId { get; set; }
public ObservableCollection<Hierarchy> ChildCollection { get; internal set; }
public ToggleState ToggleState { get; set; }
}
ViewModel
public class HierarchyViewModel : ViewModelBase
{
public ObservableCollection<Hierarchy> Hierarchy
{
get
{
return this.hierarchy;
}
private set
{
if (this.hierarchy != value)
{
this.hierarchy = value;
RaisePropertyChanged("Hierarchy");
}
}
}
}
Looking forward for your solution on this scenario,
Thanks
I modified the last solution I gave you in the following way:
1.Set the IsInTriStateMode to false;
2. The Hierarchy class now inherits the ViewModelBase and when the ToggleState is changed the UI is notified.
3. When the ToggleState is set to On, all the children nodes' ToggleStates are also set to On. This way we implement a kind of partial TriState behavior. It should be easily corrected if needed (with code only in the ViewModels).
private ToggleState toggleState;
public ToggleState ToggleState
{
get { return toggleState; }
set
{
toggleState = value;
if (value == ToggleState.On)
{
foreach (var item in ChildCollection)
{
item.ToggleState = ToggleState.On;
}
}
this.OnPropertyChanged("ToggleState");
}
}
Please let us know if this satisfies you. Kind regards,
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>