refactor: using a new DotBrushProperty instead of calling Application.TryGetResource

This commit is contained in:
leo 2024-04-17 16:16:11 +08:00
parent 3a3c0e717f
commit 1e3711e569
2 changed files with 10 additions and 14 deletions

View file

@ -131,6 +131,7 @@
<v:CommitGraph x:Name="commitGraph"
BindingDataGrid="{Binding #commitDataGrid}"
Graph="{Binding Graph}"
DotBrush="{DynamicResource Brush.Contents}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
IsHitTestVisible="False"
ClipToBounds="True"/>

View file

@ -99,19 +99,18 @@ namespace SourceGit.Views
set => SetValue(BindingDataGridProperty, value);
}
public static readonly StyledProperty<IBrush> DotBrushProperty =
AvaloniaProperty.Register<CommitGraph, IBrush>(nameof(DotBrush), Brushes.Transparent);
public IBrush DotBrush
{
get => GetValue(DotBrushProperty);
set => SetValue(DotBrushProperty, value);
}
static CommitGraph()
{
AffectsRender<CommitGraph>(BindingDataGridProperty, GraphProperty);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property.Name == "ActualThemeVariant")
{
InvalidateVisual();
}
AffectsRender<CommitGraph>(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)