Skip to content

TreeViewModel

Niclas Kristek edited this page Jul 9, 2019 · 3 revisions

The TreeViewModel abstract class provides an implementation of an IsChecked property and inherits from ViewModel. It can be used in a TreeView and, when changed, will update its parent and children with appropriate values for IsChecked. If the viewmodel has children, the TreeChildren property should be overridden accordingly.

private class FolderViewModel
    : TreeViewModel
{
    public ObservableCollection<FolderViewModel> Subfolders { get; } = new ObservableCollection<FolderViewModel>();

    protected override IEnumerable<TreeViewModel> TreeChildren => Subfolders;
}

Please note: The indeterminate state (null) of IsChecked should only be set by updates from children. The IsChecked property will be set to false if trying to set it to null directly. If you want to set the IsChecked property to null, you have to use the SetIsChecked method.

Clone this wiki locally