После некоторых исследований я попробовал это:
Вот мое древовидное представление в XAML
Код: Выделить всё
Код: Выделить всё
namespace AsurEnvironnement.SynchronisationModule.ViewModels
{
public class Synchronisation2UserControlViewModel : ViewModelBase
{
[...]
public ObservableCollection Root = new ObservableCollection();
ObservableCollection rootAChildrens = new ObservableCollection();
[...]
public override async Task InitializeStepAsync()
{
try
{
ObservableCollection rootAChildrens = new ObservableCollection();
ObservableCollection rootBChildrens = new ObservableCollection();
CheckableItem rootA = new CheckableItem() { Name = "RootA" };
CheckableItem childrenA1 = new CheckableItem() { Name = "ChildrenA1" };
CheckableItem childrenA2 = new CheckableItem() { Name = "ChildrenA2" };
rootAChildrens.Add(childrenA1);
rootAChildrens.Add(childrenA2);
rootA.Childrens = rootAChildrens;
CheckableItem rootB = new CheckableItem() { Name = "RootB" };
CheckableItem childrenB1 = new CheckableItem() { Name = "ChildrenB1" };
rootBChildrens.Add(childrenB1);
rootB.Childrens = rootBChildrens;
CheckableItem rootC = new CheckableItem() { Name = "RootC" };
Root.Add(rootA);
Root.Add(rootB);
Root.Add(rootC);
[...]
}
catch (Exception ex)
{
ProcessSnackBar(ex.Message);
_logger.LogError(ex.Message, ex);
}
finally
{
[...]
}
}
[...]
}
Код: Выделить всё
namespace AsurEnvironnement.SynchronisationModule.Models
{
public class CheckableItem : DataModelBase, INotifyPropertyChanged
{
private bool? _isChecked;
public ObservableCollection Childrens;
public bool? IsChecked
{
get { return _isChecked; }
set
{
_isChecked = value;
foreach(CheckableItem children in Childrens)
{
children.IsChecked = true;
}
}
}
public string Name { get; set; }
}
}
Но я действительно не понимаю, почему.
Подробнее здесь: https://stackoverflow.com/questions/786 ... t-populate
Мобильная версия