1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
6using System.ComponentModel;
7using System.Globalization;
18 private bool skipEvaluations =
false;
27 this.Entry = Args?.Entry;
35 await base.OnDisposeAsync();
50 [NotifyPropertyChangedFor(nameof(Value))]
51 [NotifyPropertyChangedFor(nameof(Years))]
52 [NotifyPropertyChangedFor(nameof(Months))]
53 [NotifyPropertyChangedFor(nameof(Days))]
54 [NotifyPropertyChangedFor(nameof(Hours))]
55 [NotifyPropertyChangedFor(nameof(Minutes))]
56 [NotifyPropertyChangedFor(nameof(Seconds))]
57 [NotifyPropertyChangedFor(nameof(IsNegativeDuration))]
63 base.OnPropertyChanged(e);
65 switch (e.PropertyName)
67 case nameof(this.IsNegativeDuration):
68 case nameof(this.Years):
69 case nameof(this.Months):
70 case nameof(this.Days):
71 case nameof(this.Hours):
72 case nameof(this.Minutes):
73 case nameof(this.Seconds):
77 case nameof(this.Entry):
78 if ((this.Entry is not
null) && (this.Entry.BindingContext is ParameterInfo ParameterInfo))
80 this.Value = ParameterInfo.DurationValue;
85 case nameof(this.Value):
86 if ((this.Entry is not
null) && (this.Entry.BindingContext is ParameterInfo ParameterInfo2))
87 ParameterInfo2.DurationValue = this.Value;
96 private bool isNegativeDuration;
102 private string years =
string.Empty;
108 private string months =
string.Empty;
114 private string days =
string.Empty;
120 private string hours =
string.Empty;
126 private string minutes =
string.Empty;
132 private string seconds =
string.Empty;
138 private bool yearsOk =
false;
144 private bool monthsOk =
false;
150 private bool daysOk =
false;
156 private bool hoursOk =
false;
162 private bool minutesOk =
false;
168 private bool secondsOk =
false;
175 private void PlusMinus()
177 this.IsNegativeDuration = !this.IsNegativeDuration;
185 this.skipEvaluations =
true;
187 this.IsNegativeDuration = this.Value.Negation;
188 this.Years = ComponentToString(this.Value.Years);
189 this.Months = ComponentToString(this.Value.Months);
190 this.Days = ComponentToString(this.Value.Days);
191 this.Hours = ComponentToString(this.Value.Hours);
192 this.Minutes = ComponentToString(this.Value.Minutes);
193 this.Seconds = ComponentToString(this.Value.Seconds);
195 this.skipEvaluations =
false;
198 private static string ComponentToString(
int Value)
203 return Value.ToString(CultureInfo.InvariantCulture);
206 private static string ComponentToString(
double Value)
211 return Value.ToString(CultureInfo.InvariantCulture);
219 if (this.skipEvaluations)
223 StringBuilder sb =
new();
225 if (this.IsNegativeDuration)
230 if (!
string.IsNullOrEmpty(this.Years))
233 sb.Append(this.Years);
235 this.YearsOk =
int.TryParse(this.Years, out
_);
240 if (!
string.IsNullOrEmpty(this.Months))
243 sb.Append(this.Months);
245 this.MonthsOk =
int.TryParse(this.Months, out
_);
248 this.MonthsOk =
true;
250 if (!
string.IsNullOrEmpty(this.Days))
253 sb.Append(this.Days);
255 this.DaysOk =
int.TryParse(this.Days, out
_);
260 bool IsHours = !
string.IsNullOrEmpty(this.Hours);
261 bool IsMinutes = !
string.IsNullOrEmpty(this.Minutes);
262 bool IsSeconds = !
string.IsNullOrEmpty(this.Seconds);
264 if (IsHours || IsMinutes || IsSeconds)
271 sb.Append(this.Hours);
273 this.HoursOk =
int.TryParse(this.Hours, out
_);
280 sb.Append(this.Minutes);
282 this.MinutesOk =
int.TryParse(this.Minutes, out
_);
285 this.MinutesOk =
true;
289 sb.Append(this.Seconds);
294 this.SecondsOk =
true;
299 this.MinutesOk =
true;
300 this.SecondsOk =
true;
A customizable entry control that allows setting views on the left and right sides of the entry.
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 OnDisposeAsync()
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.