Skip to content

Commit

Permalink
refactor: using a new DotBrushProperty instead of calling Application…
Browse files Browse the repository at this point in the history
….TryGetResource
  • Loading branch information
love-linger committed Apr 17, 2024
1 parent 3a3c0e7 commit 1e3711e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/Views/Histories.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
23 changes: 9 additions & 14 deletions src/Views/Histories.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,18 @@ public DataGrid BindingDataGrid
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);

if (change.Property.Name == "ActualThemeVariant")
{
InvalidateVisual();
}
AffectsRender<CommitGraph>(BindingDataGridProperty, GraphProperty, DotBrushProperty);
}

public override void Render(DrawingContext context)
Expand Down Expand Up @@ -153,11 +152,7 @@ public override void Render(DrawingContext context)
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)
Expand Down

0 comments on commit 1e3711e

Please sign in to comment.