From c28b8b3ebbe91c6d4fade11a3c4f32abe29f9a40 Mon Sep 17 00:00:00 2001 From: Mccree Lee Date: Tue, 6 Aug 2024 22:53:42 +0800 Subject: [PATCH 1/2] fix: WaveProgress strange behavior Value sets to 49 after changing theme --- SukiUI/Controls/WaveProgress.axaml | 18 ++++++++---------- SukiUI/Controls/WaveProgress.axaml.cs | 24 ++++++++---------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/SukiUI/Controls/WaveProgress.axaml b/SukiUI/Controls/WaveProgress.axaml index 34a0a8e02..4ed76f76d 100644 --- a/SukiUI/Controls/WaveProgress.axaml +++ b/SukiUI/Controls/WaveProgress.axaml @@ -1,5 +1,4 @@ - - - - - + + + @@ -39,7 +38,7 @@ - @@ -82,9 +80,9 @@ VerticalAlignment="Center" Classes="h2" Foreground="{TemplateBinding Value, - Converter={StaticResource WValueColorConvert}}" + Converter={StaticResource WValueColorConverter}}" Text="{TemplateBinding Value, - Converter={StaticResource WValueTextConvert}}"> + Converter={StaticResource WValueTextConverter}}"> diff --git a/SukiUI/Controls/WaveProgress.axaml.cs b/SukiUI/Controls/WaveProgress.axaml.cs index b6b5f8af6..e9eec54d0 100644 --- a/SukiUI/Controls/WaveProgress.axaml.cs +++ b/SukiUI/Controls/WaveProgress.axaml.cs @@ -9,6 +9,7 @@ public partial class WaveProgress : UserControl public WaveProgress() { InitializeComponent(); + var theme = SukiTheme.GetInstance(); theme.OnBaseThemeChanged += _ => { @@ -27,33 +28,24 @@ private void InitializeComponent() AvaloniaXamlLoader.Load(this); } - private double _value = 50; + public static readonly StyledProperty ValueProperty = + AvaloniaProperty.Register(nameof(Value), defaultValue: 50); public double Value { - get => _value; + get => GetValue(ValueProperty); set { - if (value is < 0 or > 100) - return; - - SetValue(ValueProperty,value); + if (value is >= 0 and <= 100) + SetValue(ValueProperty, value); } } - - public static readonly StyledProperty ValueProperty = - AvaloniaProperty.Register(nameof(Value), defaultValue: 50); - - public static readonly StyledProperty IsTextVisibleProperty = AvaloniaProperty.Register(nameof(IsTextVisible), defaultValue: true); public bool IsTextVisible { - get { return GetValue(IsTextVisibleProperty); } - set - { - SetValue(IsTextVisibleProperty, value); - } + get => GetValue(IsTextVisibleProperty); + set => SetValue(IsTextVisibleProperty, value); } } \ No newline at end of file From b2ac08aa2b588a1b9bd581a8c7c456a767e750e5 Mon Sep 17 00:00:00 2001 From: Mccree Lee Date: Tue, 6 Aug 2024 23:17:17 +0800 Subject: [PATCH 2/2] fix: crushes when new SukiWindow --- SukiUI/Controls/SukiWindow.axaml | 10 +++-- SukiUI/Controls/SukiWindow.axaml.cs | 63 +++++++++++++---------------- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/SukiUI/Controls/SukiWindow.axaml b/SukiUI/Controls/SukiWindow.axaml index 9ae128827..4bd9993b0 100644 --- a/SukiUI/Controls/SukiWindow.axaml +++ b/SukiUI/Controls/SukiWindow.axaml @@ -28,8 +28,10 @@ Style="{TemplateBinding BackgroundStyle}" TransitionTime="{TemplateBinding BackgroundTransitionTime}" TransitionsEnabled="{TemplateBinding BackgroundTransitionsEnabled}" /> - - + + @@ -78,7 +80,7 @@ - + @@ -116,7 +118,7 @@ - + diff --git a/SukiUI/Controls/SukiWindow.axaml.cs b/SukiUI/Controls/SukiWindow.axaml.cs index f6674de3d..faae90209 100644 --- a/SukiUI/Controls/SukiWindow.axaml.cs +++ b/SukiUI/Controls/SukiWindow.axaml.cs @@ -30,8 +30,7 @@ public double TitleFontSize } public static readonly StyledProperty TitleFontWeightProperty = - AvaloniaProperty.Register(nameof(TitleFontWeight), - defaultValue: FontWeight.Bold); + AvaloniaProperty.Register(nameof(TitleFontWeight), defaultValue: FontWeight.Bold); public FontWeight TitleFontWeight { @@ -83,8 +82,7 @@ public AvaloniaList? MenuItems get => GetValue(MenuItemsProperty); set => SetValue(MenuItemsProperty, value); } - - + public static readonly StyledProperty CanMinimizeProperty = AvaloniaProperty.Register(nameof(CanMinimize), defaultValue: true); @@ -103,7 +101,7 @@ public bool CanMove set => SetValue(CanMoveProperty, value); } - // BACKGROUND PROPERTIES + // Background properties public static readonly StyledProperty BackgroundAnimationEnabledProperty = AvaloniaProperty.Register(nameof(BackgroundAnimationEnabled), defaultValue: false); @@ -116,7 +114,6 @@ public bool BackgroundAnimationEnabled public static readonly StyledProperty BackgroundStyleProperty = AvaloniaProperty.Register(nameof(BackgroundStyle), defaultValue: SukiBackgroundStyle.Bubble); - /// public SukiBackgroundStyle BackgroundStyle @@ -137,7 +134,6 @@ public string? BackgroundShaderFile public static readonly StyledProperty BackgroundShaderCodeProperty = AvaloniaProperty.Register(nameof(BackgroundShaderCode)); - /// public string? BackgroundShaderCode @@ -166,10 +162,13 @@ public double BackgroundTransitionTime set => SetValue(BackgroundTransitionTimeProperty, value); } - public static readonly StyledProperty RightWindowTitleBarControlsProperty = AvaloniaProperty.Register(nameof(RightWindowTitleBarControls), defaultValue: new Avalonia.Controls.Controls()); + public static readonly StyledProperty RightWindowTitleBarControlsProperty = + AvaloniaProperty.Register(nameof(RightWindowTitleBarControls), + defaultValue: new Avalonia.Controls.Controls()); /// - /// Controls that are displayed on the right side of the title bar, to the left of the normal window control buttons. (Displays provided controls right-to-left) + /// Controls that are displayed on the right side of the title bar, + /// to the left of the normal window control buttons. (Displays provided controls right-to-left) /// public Avalonia.Controls.Controls RightWindowTitleBarControls { @@ -180,25 +179,25 @@ public Avalonia.Controls.Controls RightWindowTitleBarControls public SukiWindow() { MenuItems = new AvaloniaList(); + RightWindowTitleBarControls = new Avalonia.Controls.Controls(); } private IDisposable? _subscriptionDisposables; - private SukiBackground? _background; protected override void OnLoaded(RoutedEventArgs e) { base.OnLoaded(e); + if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return; - if (desktop.MainWindow is SukiWindow s && s != this) + if (desktop.MainWindow is SukiWindow window && window != this) { - if (Icon == null) Icon = s.Icon; + Icon ??= window.Icon; // This would be nice to do, but obviously LogoContent is a control and you can't attach it twice. // if (LogoContent is null) LogoContent = s.LogoContent; } } - - + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); @@ -213,10 +212,12 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) if (e.NameScope.Get