是否可以在XAML中创建一个Line(后面没有任何C#代码)来对齐布局容器(如Grid)中的一行?
我想有效地拥有:
<Grid>
<Line StrokeThickness="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Stroke="Red"/>
</Grid>
我需要使用StrokeDashArray
和StrokeDashOffset
,否则我只会使用Border
控件并将BorderThickness设置为"0,0,0,1"
...
感谢您的任何想法!
答案 0 :(得分:10)
详细说明kanchirk的回应,这对我有用:
<Path StrokeThickness="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Data="M0,0 L1,0"
Stretch="Fill"
StrokeEndLineCap="Square"
StrokeStartLineCap="Square"
Stroke="Red"/>
Line
:
<Line StrokeThickness="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
X2="1"
Stretch="Fill"
StrokeEndLineCap="Square"
StrokeStartLineCap="Square"
Stroke="Red"/>
答案 1 :(得分:1)
我认为你需要像这样使用路径
<Grid x:Name="LayoutRoot" Background="White">
<Path Fill="Red" Stretch="Fill" Stroke="Black" StrokeDashArray="1" Height="4" Margin="8,0,7,7" VerticalAlignment="Bottom" UseLayoutRounding="False" Data="M8,127 L457,127" StrokeThickness="13"/>
</Grid>
希望这有助于。 Expression Blend是这类挑战必不可少的,甚至是VS 2010 RC1(现在)
答案 2 :(得分:1)
这个怎么样?
<Line x:Name="line"
StrokeThickness="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Stroke="Red"
X2="{Binding ActualWidth, ElementName=line, Mode=OneWay}"
Stretch="Fill"
StrokeStartLineCap="Square"
StrokeEndLineCap="Square"/>