using Avalonia; using Avalonia.Controls; namespace AutoCat.Views; public partial class ReportTextItem : UserControl { #region Dependency properties public static readonly StyledProperty LabelProperty = AvaloniaProperty.Register(nameof(Label)); public static readonly StyledProperty ValueProperty = AvaloniaProperty.Register(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((v, e) => v.ValueChanged(e)); ValueProperty.Changed.AddClassHandler((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; } } }