From 1e3711e569ab7ba8885fb502bfc1024f37f72642 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 17 Apr 2024 16:16:11 +0800 Subject: [PATCH] refactor: using a new DotBrushProperty instead of calling Application.TryGetResource --- src/Views/Histories.axaml | 1 + src/Views/Histories.axaml.cs | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index 0dfedc9a..9077d500 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -131,6 +131,7 @@ diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 4a214784..13f05aff 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -99,19 +99,18 @@ namespace SourceGit.Views set => SetValue(BindingDataGridProperty, value); } - static CommitGraph() + public static readonly StyledProperty DotBrushProperty = + AvaloniaProperty.Register(nameof(DotBrush), Brushes.Transparent); + + public IBrush DotBrush { - AffectsRender(BindingDataGridProperty, GraphProperty); + get => GetValue(DotBrushProperty); + set => SetValue(DotBrushProperty, value); } - protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + static CommitGraph() { - base.OnPropertyChanged(change); - - if (change.Property.Name == "ActualThemeVariant") - { - InvalidateVisual(); - } + AffectsRender(BindingDataGridProperty, GraphProperty, DotBrushProperty); } public override void Render(DrawingContext context) @@ -153,11 +152,7 @@ namespace SourceGit.Views DrawCurves(context, top, bottom); // Draw connect dots - Brush dotFill = null; - if (App.Current.TryGetResource("Brush.Contents", App.Current.ActualThemeVariant, out object res) && res is SolidColorBrush) - { - dotFill = res as SolidColorBrush; - } + IBrush dotFill = DotBrush; foreach (var dot in graph.Dots) { if (dot.Center.Y < top)