Reputation: 19396
I would like to use a line in a MAUI project, and this is the documentation:
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/shapes/line?view=net-maui-7.0
But i would like, in an horizontal line, to set that automatically the line use all the space from left to right. I don't see stretch options like another controls.
I could set a very long length, for example 10000, but I would like to know if there is a better way.
Thanks.
Upvotes: 4
Views: 2962
Reputation: 2995
A Line
is a Shape
with the Aspect
property of type Stretch
.
To stretch a Line
to fill the space of its layout, below a Grid
row with default horizontal layout Fill
, use the Aspect
value Uniform
:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Line Grid.Row="0" Stroke="Red" X1="0" X2="100" Aspect="Uniform" />
<Line Grid.Row="1" Stroke="Green" X1="0" X2="100" Aspect="None" />
</Grid>
Upvotes: 1
Reputation: 20728
To answer directly your question: since X2
is bindable, you can bind it to the width of itself:
<Line Stroke="Red" X2="{Binding Width, Source={RelativeSource Self}}" HorizontalOptions="Fill" StrokeThickness="3" />
My advice: MS has been using BoxView
or BorderView
for lines since forever, I guess it's better performance-wise as well. You should use the other solution instead unless you absolutely have to use Line.
Upvotes: 10
Reputation: 81
try the below code for horizontal line
<Style x:Key="HorizontalBoarder" TargetType="BoxView">
<Setter Property="BackgroundColor" Value="White" />
<Setter Property="HeightRequest" Value="1" />
<Setter Property="HorizontalOptions" Value="FillAndExpand" />
</Style>
<BoxView
Margin="0,5"
Style="{StaticResource HorizontalBoarder}" />
Upvotes: 0