Skip to content

Commit

Permalink
datagrid lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jinek committed Oct 18, 2024
1 parent a807e3e commit 4527aec
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@

</Grid>

<Border Name="VerticalSeparator"
<helpers:FastLineSeparator Name="VerticalSeparator"
Grid.Column="1"
Width="1"
Orientation="Vertical"
VerticalAlignment="Stretch"
BorderThickness="1"
BorderBrush="{TemplateBinding BorderBrush}"
Width="1"
Brush="{TemplateBinding BorderBrush}"
IsVisible="{TemplateBinding AreSeparatorsVisible}" />
</Grid>
</ControlTemplate>
Expand Down Expand Up @@ -313,14 +313,23 @@
Background="{TemplateBinding Background}"
Margin="0,1" />

<helpers:FastLineSeparator Grid.Row="0"
VerticalAlignment="Bottom"
Grid.ColumnSpan="3"
Grid.Column="0"
Orientation="Horizontal"
Brush="{TemplateBinding BorderBrush}"
Margin="-1,0" />

<!--
<Border Grid.Row="0"
VerticalAlignment="Bottom"
Grid.ColumnSpan="3"
Grid.Column="0"
Height="1"
Height="2"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
Margin="-1,0" />
Margin="-1,0" />-->

<!--<DataGridColumnHeader Name="PART_TopRightCornerHeader" Grid.Column="2"
Background="{DynamicResource ThemeAccentBrush}"/>-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;

namespace Consolonia.Themes.TurboVision.Templates.Controls.Helpers
{
public class FastLineSeparator : Control
{
public static readonly StyledProperty<Orientation> OrientationProperty =
AvaloniaProperty.Register<FastLineSeparator, Orientation>(nameof(Orientation), Orientation.Horizontal);

public Orientation Orientation
{
get => GetValue(OrientationProperty);
set => SetValue(OrientationProperty, value);
}

public static readonly StyledProperty<IBrush> BrushProperty =
AvaloniaProperty.Register<FastLineSeparator, IBrush>(nameof(Brush), Brushes.Black);

public IBrush Brush
{
get => GetValue(BrushProperty);
set => SetValue(BrushProperty, value);
}


public FastLineSeparator()
{
AffectsRender<FastLineSeparator>(OrientationProperty);
}

protected override Size MeasureOverride(Size availableSize)
{
return Orientation == Orientation.Horizontal
? new Size(0, 1)
: new Size(1, 0);
}

protected override Size ArrangeOverride(Size finalSize)
{
return finalSize;
}

public override void Render(DrawingContext context)
{
var pen = new Pen(Brush);

if (Orientation == Orientation.Horizontal)
{
// Draw a horizontal line across the control's width
var startPoint = new Point(0, Bounds.Height / 2);
var endPoint = new Point(Bounds.Width-1, Bounds.Height / 2);
context.DrawLine(pen, startPoint, endPoint);
}
else
{
// Draw a vertical line across the control's height
var startPoint = new Point(Bounds.Width / 2, 0);
var endPoint = new Point(Bounds.Width / 2, Bounds.Height-1);
context.DrawLine(pen, startPoint, endPoint);
}
}

}
}

0 comments on commit 4527aec

Please sign in to comment.