Add time zones settings panel

This commit is contained in:
2024-10-04 17:32:10 -04:00
parent 4751ae476d
commit 50fd78a3c3
11 changed files with 657 additions and 37 deletions

View File

@@ -1,7 +1,61 @@
namespace WorldClockStatusWindow;
using System;
using System.Collections;
using System.ComponentModel;
using System.Linq;
using System.Text.Json.Serialization;
public class TimeZoneEntry
namespace WorldClockStatusWindow;
public class TimeZoneEntry : INotifyDataErrorInfo
{
public string Label { get; set; }
private readonly DataErrorDictionary _dataErrorDictionary;
public TimeZoneEntry()
{
_dataErrorDictionary = new DataErrorDictionary();
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
}
private string _label;
public string Label
{
get => _label;
set
{
if (!ValidateLabel(value))
return;
_label = value;
}
}
public string TimeZoneId { get; set; }
[JsonIgnore]
public bool HasErrors => _dataErrorDictionary.Any();
public IEnumerable GetErrors(string propertyName)
{
return _dataErrorDictionary.GetErrors(propertyName);
}
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
private void DataErrorDictionaryErrorsChanged(object sender, DataErrorsChangedEventArgs e)
{
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(e.PropertyName));
}
private bool ValidateLabel(string newValue)
{
_dataErrorDictionary.ClearErrors(nameof(Label));
if (!string.IsNullOrWhiteSpace(newValue))
return true;
_dataErrorDictionary.AddError(nameof(Label), "Label cannot be empty");
return false;
}
}