Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
WorkspaceSettingViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
4using System.Windows.Input;
5using System.Windows.Media;
8
10{
15 public class WorkspaceSettingViewModel<T> : ObservableObject, IWorkspaceSettingViewModel
16 {
20 public WorkspaceSetting<T> Setting { get; }
21
25 public string Label { get; }
26
30 public string Tooltip { get; }
31
35 public string Icon { get; }
36
40 public Geometry IconGeometry { get; }
41
45 public bool HasChanged => Setting?.HasChanged ?? false;
46
50 public bool HasDefaultValue => Setting?.HasDefaultValue ?? true;
51
52 private bool _supportResetToDefault;
57 {
58 get => _supportResetToDefault;
59 set => SetProperty(ref _supportResetToDefault, value);
60 }
61
65 public ICommand ResetCommand { get; }
66
70 public ICommand SetToDefaultCommand { get; }
71
75 public T Value
76 {
77 get => Setting.Value;
78 set
79 {
80 if (!Setting.Value.Equals(value))
81 {
82 Setting.Value = value;
83 OnPropertyChanged();
84 OnPropertyChanged(nameof(HasChanged));
85 OnPropertyChanged(nameof(HasDefaultValue));
86 }
87 }
88 }
89
93 public T MinValue => Setting.MinValue;
94
98 public T MaxValue => Setting.MaxValue;
99
104 public object UntypedMinValue => Setting.UntypedMinValue!;
105
110 public object UntypedMaxValue => Setting.UntypedMaxValue!;
111
115 public Type ValueType => typeof(T);
116
121 public object UntypedValue
122 {
123 get => Value!;
124 set => Value = (T)Convert.ChangeType(value, typeof(T));
125 }
126
130 public DataTemplate EditorTemplate { get; }
131
142 public WorkspaceSettingViewModel(WorkspaceSetting<T> setting, string label, string tooltip, string icon, Geometry iconGeometry, DataTemplate editorTemplate, bool supportResetToDefault)
143 {
144 Setting = setting;
145 Label = label;
146 Tooltip = tooltip;
147 Icon = icon;
148 IconGeometry = iconGeometry;
149 ResetCommand = new RelayCommand(() =>
150 {
151 setting?.Reset();
152 OnPropertyChanged(nameof(Value));
153 OnPropertyChanged(nameof(HasChanged));
154 OnPropertyChanged(nameof(HasDefaultValue));
155 });
156 SetToDefaultCommand = new RelayCommand(() =>
157 {
159 {
160 setting?.SetToDefault();
161 }
162 OnPropertyChanged(nameof(Value));
163 OnPropertyChanged(nameof(HasDefaultValue));
164 OnPropertyChanged(nameof(HasChanged));
165 });
166 EditorTemplate = editorTemplate;
167 SupportResetToDefault = supportResetToDefault;
168
169 if (setting != null)
170 {
171 setting.PropertyChanged += (sender, e) =>
172 {
173 switch(e.PropertyName)
174 {
175 case nameof(WorkspaceSetting<T>.Value): OnPropertyChanged(nameof(Value)); break;
176 case nameof(WorkspaceSetting<T>.HasChanged): OnPropertyChanged(nameof(HasChanged)); break;
177 case nameof(WorkspaceSetting<T>.HasDefaultValue): OnPropertyChanged(nameof(HasDefaultValue)); break;
178 default: break;
179 }
180 };
181 }
182 }
183 }
184}
void Reset()
Set the Value to the SnapshotValue
void SetToDefault()
Set the Value to the DefaultValue
bool SupportResetToDefault
Support for resetting the setting value to the default value.
DataTemplate EditorTemplate
Data template to assign a setting dependent editor view.
bool HasChanged
True, if the setting value is not the snapshot value.
WorkspaceSetting< T > Setting
WorkspaceSetting<T> that is managed by this view model
bool HasDefaultValue
True if the setting value is the default value.
ICommand SetToDefaultCommand
Command to set the setting value back to the default value.
WorkspaceSettingViewModel(WorkspaceSetting< T > setting, string label, string tooltip, string icon, Geometry iconGeometry, DataTemplate editorTemplate, bool supportResetToDefault)
Constructor for the WorkspaceSettingViewModel<T>
ICommand ResetCommand
Command to set the setting value back to the snapshot value.