madaxe2020
Well-known member
- Joined
- Sep 7, 2020
- Messages
- 50
- Programming Experience
- 5-10
Morning,
I have a 'View Model' that creates a data structure that is variable and up to 6 levels deep. I'm struggling writing the XAML to display the treeview can somebody help, the treeview should also have check boxes also.
the goal will be to set the parents check box if all children are checked and so on up the treeview.
thanks
madaxe
I have a 'View Model' that creates a data structure that is variable and up to 6 levels deep. I'm struggling writing the XAML to display the treeview can somebody help, the treeview should also have check boxes also.
the goal will be to set the parents check box if all children are checked and so on up the treeview.
thanks
madaxe
ViewModel:
using System.Collections.Generic;
using treeview.Models;
namespace treeview.ViewModels
{
public class ThingViewModel: ViewModelBase
{
ThingModel _thingModel;
public bool? IsChecked { get; set; }
public bool IsInitiallySelected { get; set; }
public ThingModel Parent => _thingModel.Parent;
public List<ThingModel> Children => _thingModel.Children;
public string Name => _thingModel.Name;
public List<ThingViewModel> ViewModelChildren => GetViewModelChildren();
public ThingViewModel ViewModelParent => GetViewModelParent();
public ThingViewModel(ThingModel thingModel)
{
_thingModel = thingModel;
}
private List<ThingViewModel> GetViewModelChildren()
{
List<ThingViewModel> thingViewModels = new List<ThingViewModel>();
foreach(ThingModel thingModel in Children)
{
thingViewModels.Add(new ThingViewModel(thingModel));
}
return thingViewModels;
}
private ThingViewModel GetViewModelParent()
{
return new ThingViewModel(Parent);
}
}
}