1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
5using System.ComponentModel;
6using System.Globalization;
17 private bool skipEvaluations =
false;
26 this.Entry = Args?.Entry;
34 await base.OnDispose();
49 [NotifyPropertyChangedFor(nameof(Value))]
50 [NotifyPropertyChangedFor(nameof(Years))]
51 [NotifyPropertyChangedFor(nameof(Months))]
52 [NotifyPropertyChangedFor(nameof(Days))]
53 [NotifyPropertyChangedFor(nameof(Hours))]
54 [NotifyPropertyChangedFor(nameof(Minutes))]
55 [NotifyPropertyChangedFor(nameof(Seconds))]
56 [NotifyPropertyChangedFor(nameof(IsNegativeDuration))]
62 base.OnPropertyChanged(e);
64 switch (e.PropertyName)
66 case nameof(this.IsNegativeDuration):
67 case nameof(this.Years):
68 case nameof(this.Months):
69 case nameof(this.Days):
70 case nameof(this.Hours):
71 case nameof(this.Minutes):
72 case nameof(this.Seconds):
76 case nameof(this.Entry):
77 if ((this.Entry is not
null) && (this.Entry.BindingContext is ParameterInfo ParameterInfo))
79 this.Value = ParameterInfo.DurationValue;
84 case nameof(this.Value):
85 if ((this.Entry is not
null) && (this.Entry.BindingContext is ParameterInfo ParameterInfo2))
86 ParameterInfo2.DurationValue = this.Value;
95 private bool isNegativeDuration;
101 private string years =
string.Empty;
107 private string months =
string.Empty;
113 private string days =
string.Empty;
119 private string hours =
string.Empty;
125 private string minutes =
string.Empty;
131 private string seconds =
string.Empty;
137 private bool yearsOk =
false;
143 private bool monthsOk =
false;
149 private bool daysOk =
false;
155 private bool hoursOk =
false;
161 private bool minutesOk =
false;
167 private bool secondsOk =
false;
174 private void PlusMinus()
176 this.IsNegativeDuration = !this.IsNegativeDuration;
184 this.skipEvaluations =
true;
186 this.IsNegativeDuration = this.Value.Negation;
187 this.Years = ComponentToString(this.Value.Years);
188 this.Months = ComponentToString(this.Value.Months);
189 this.Days = ComponentToString(this.Value.Days);
190 this.Hours = ComponentToString(this.Value.Hours);
191 this.Minutes = ComponentToString(this.Value.Minutes);
192 this.Seconds = ComponentToString(this.Value.Seconds);
194 this.skipEvaluations =
false;
197 private static string ComponentToString(
int Value)
202 return Value.ToString(CultureInfo.InvariantCulture);
205 private static string ComponentToString(
double Value)
210 return Value.ToString(CultureInfo.InvariantCulture);
218 if (this.skipEvaluations)
222 StringBuilder sb =
new();
224 if (this.IsNegativeDuration)
229 if (!
string.IsNullOrEmpty(this.Years))
232 sb.Append(this.Years);
234 this.YearsOk =
int.TryParse(this.Years, out _);
239 if (!
string.IsNullOrEmpty(this.Months))
242 sb.Append(this.Months);
244 this.MonthsOk =
int.TryParse(this.Months, out _);
247 this.MonthsOk =
true;
249 if (!
string.IsNullOrEmpty(this.Days))
252 sb.Append(this.Days);
254 this.DaysOk =
int.TryParse(this.Days, out _);
259 bool IsHours = !
string.IsNullOrEmpty(this.Hours);
260 bool IsMinutes = !
string.IsNullOrEmpty(this.Minutes);
261 bool IsSeconds = !
string.IsNullOrEmpty(this.Seconds);
263 if (IsHours || IsMinutes || IsSeconds)
270 sb.Append(this.Hours);
272 this.HoursOk =
int.TryParse(this.Hours, out _);
279 sb.Append(this.Minutes);
281 this.MinutesOk =
int.TryParse(this.Minutes, out _);
284 this.MinutesOk =
true;
288 sb.Append(this.Seconds);
293 this.SecondsOk =
true;
298 this.MinutesOk =
true;
299 this.SecondsOk =
true;
The view model to bind to for when displaying the duration.
DurationViewModel(DurationNavigationArgs? Args)
Creates an instance of the DurationViewModel class.
void SplitDuration()
Split the current duration value into components.
void EvaluateDuration()
Evaluates the current duration.
override void OnPropertyChanged(PropertyChangedEventArgs e)
override async Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
A view model that holds the XMPP state.
Helps with parsing of commong data types.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Represents a duration value, as defined by the xsd:duration data type: http://www....
static bool TryParse(string s, out Duration Result)
Tries to parse a duration value.