AutoCatAvalonia/AutoCat/Views/ReportTextItem.axaml.cs

62 lines
1.4 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace AutoCat.Views;
public partial class ReportTextItem : UserControl
{
#region Dependency properties
public static readonly StyledProperty<string> LabelProperty =
AvaloniaProperty.Register<ReportTextItem, string>(nameof(Label));
public static readonly StyledProperty<string> ValueProperty =
AvaloniaProperty.Register<ReportTextItem, string>(nameof(Value));
#endregion
#region Properties
public string Label
{
get => GetValue(LabelProperty);
set => SetValue(LabelProperty, value);
}
public string Value
{
get => GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}
#endregion
static ReportTextItem()
{
LabelProperty.Changed.AddClassHandler<ReportTextItem>((v, e) => v.ValueChanged(e));
ValueProperty.Changed.AddClassHandler<ReportTextItem>((v, e) => v.ValueChanged(e));
}
public ReportTextItem()
{
InitializeComponent();
}
private void ValueChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.NewValue is not string newValue)
return;
if (e.Property == LabelProperty)
{
LabelBlock.Text = newValue;
}
if (e.Property == ValueProperty)
{
ValueBlock.Text = newValue;
}
}
}