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" <v:CommitGraph x:Name="commitGraph"
BindingDataGrid="{Binding #commitDataGrid}" BindingDataGrid="{Binding #commitDataGrid}"
Graph="{Binding Graph}" Graph="{Binding Graph}"
DotBrush="{DynamicResource Brush.Contents}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
IsHitTestVisible="False" IsHitTestVisible="False"
ClipToBounds="True"/> ClipToBounds="True"/>

View file

@ -99,19 +99,18 @@ namespace SourceGit.Views
set => SetValue(BindingDataGridProperty, value); set => SetValue(BindingDataGridProperty, value);
} }
static CommitGraph() public static readonly StyledProperty<IBrush> DotBrushProperty =
AvaloniaProperty.Register<CommitGraph, IBrush>(nameof(DotBrush), Brushes.Transparent);
public IBrush DotBrush
{ {
AffectsRender<CommitGraph>(BindingDataGridProperty, GraphProperty); get => GetValue(DotBrushProperty);
set => SetValue(DotBrushProperty, value);
} }
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) static CommitGraph()
{ {
base.OnPropertyChanged(change); AffectsRender<CommitGraph>(BindingDataGridProperty, GraphProperty, DotBrushProperty);
if (change.Property.Name == "ActualThemeVariant")
{
InvalidateVisual();
}
} }
public override void Render(DrawingContext context) public override void Render(DrawingContext context)
@ -153,11 +152,7 @@ namespace SourceGit.Views
DrawCurves(context, top, bottom); DrawCurves(context, top, bottom);
// Draw connect dots // Draw connect dots
Brush dotFill = null; IBrush dotFill = DotBrush;
if (App.Current.TryGetResource("Brush.Contents", App.Current.ActualThemeVariant, out object res) && res is SolidColorBrush)
{
dotFill = res as SolidColorBrush;
}
foreach (var dot in graph.Dots) foreach (var dot in graph.Dots)
{ {
if (dot.Center.Y < top) if (dot.Center.Y < top)