在纯XAML中,是否可以使Line与Grid的一部分对齐?

时间:2010-03-12 05:03:46

标签: silverlight xaml line

是否可以在XAML中创建一个Line(后面没有任何C#代码)来对齐布局容器(如Grid)中的一行?

我想有效地拥有:

<Grid>
    <Line StrokeThickness="1" 
          HorizontalAlignment="Stretch" 
          VerticalAlignment="Bottom" 
          Stroke="Red"/>
</Grid>

我需要使用StrokeDashArrayStrokeDashOffset,否则我只会使用Border控件并将BorderThickness设置为"0,0,0,1" ...

感谢您的任何想法!

3 个答案:

答案 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"/> 
相关问题