using System; using System.Windows.Input; using Avalonia; using Avalonia.Controls; namespace LANCommander.Launcher.Views.Components; public partial class PageHeaderView : UserControl { public static readonly StyledProperty TitleProperty = AvaloniaProperty.Register(nameof(Title)); public static readonly StyledProperty SubtitleProperty = AvaloniaProperty.Register(nameof(Subtitle)); public static readonly StyledProperty BackButtonTextProperty = AvaloniaProperty.Register(nameof(BackButtonText)); public static readonly StyledProperty BackCommandProperty = AvaloniaProperty.Register(nameof(BackCommand)); public static readonly StyledProperty ShowBackButtonProperty = AvaloniaProperty.Register(nameof(ShowBackButton)); public string? Title { get => GetValue(TitleProperty); set => SetValue(TitleProperty, value); } public string? Subtitle { get => GetValue(SubtitleProperty); set => SetValue(SubtitleProperty, value); } public string? BackButtonText { get => GetValue(BackButtonTextProperty); set => SetValue(BackButtonTextProperty, value); } public ICommand? BackCommand { get => GetValue(BackCommandProperty); set => SetValue(BackCommandProperty, value); } public bool ShowBackButton { get => GetValue(ShowBackButtonProperty); set => SetValue(ShowBackButtonProperty, value); } public PageHeaderView() { InitializeComponent(); } protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); if (change.Property == TitleProperty) { var titleText = this.FindControl("TitleText"); if (titleText != null) titleText.Text = Title; } else if (change.Property == SubtitleProperty) { var subtitleText = this.FindControl("SubtitleText"); if (subtitleText != null) { subtitleText.Text = Subtitle; subtitleText.IsVisible = !string.IsNullOrEmpty(Subtitle); } } else if (change.Property == BackButtonTextProperty || change.Property == BackCommandProperty || change.Property == ShowBackButtonProperty) { var backButton = this.FindControl