namespace OMNIPruefung.ViewModels { using OMNIPruefung.ViewModels.Base; using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows.Input; public class OptionVM : NodeVM { const int INDENT = 13; private readonly NodeVM parent; public OptionVM(NodeVM parent) { this.parent = parent; this.parent.PropertyChanged += this.Parent_PropertyChanged; } public event Action OptionSelected; private int indent = INDENT; public int Indent { get => this.indent; set { this.indent = value; this.NotifyPropertyChanged(nameof(this.Indent)); } } public override string Header { get => this.parent?.Header; set => this.NotifyPropertyChanged(this.Header); } private bool expanded; public bool IsExpanded { get => this.expanded; set { this.expanded = value; this.NotifyPropertyChanged(nameof(this.IsExpanded)); } } private bool selected; public bool IsSelected { get => this.selected; set { if (!this.selected && value) { this.OptionSelected?.Invoke(); } this.selected = value; this.NotifyPropertyChanged(nameof(this.IsSelected)); } } public ICommand ToggleNodes => new Command(() => { this.IsExpanded = !this.IsExpanded; }); public ObservableCollection Options { get; } = new ObservableCollection(); internal void Add(OptionVM option) { App.Invoke(() => this.Options.Add(option)); } internal void Clear() { App.Invoke(() => this.Options.Clear()); } internal void SetIndentation(int indent = INDENT) { this.indent = indent; foreach (var option in this.Options) { option.SetIndentation(this.indent + INDENT); } } protected virtual void Parent_PropertyChanged(object sender, PropertyChangedEventArgs args) { this.NotifyPropertyChanged(nameof(this.Header)); this.NotifyPropertyChanged(nameof(this.Indent)); this.NotifyPropertyChanged(nameof(this.IsExpanded)); this.NotifyPropertyChanged(nameof(this.IsSelected)); } } }