Files

58 lines
1001 B
C#

using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
namespace AxCopilot.ViewModels;
public class ColorRowModel : INotifyPropertyChanged
{
private string _hex;
public string Label { get; init; } = "";
public string Property { get; init; } = "";
public string Hex
{
get
{
return _hex;
}
set
{
_hex = value;
OnPropertyChanged("Hex");
OnPropertyChanged("Preview");
}
}
public SolidColorBrush Preview
{
get
{
try
{
return new SolidColorBrush((Color)ColorConverter.ConvertFromString(Hex));
}
catch
{
return new SolidColorBrush(Colors.Transparent);
}
}
}
public event PropertyChangedEventHandler? PropertyChanged;
public ColorRowModel(string label, string property, string hex)
{
Label = label;
Property = property;
_hex = hex;
}
protected void OnPropertyChanged([CallerMemberName] string? n = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(n));
}
}