6

是否可以在 XAML 中创建一条线(没有任何 C# 代码)来对齐布局容器(如网格)内的一条线?

我想有效地拥有:

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

我需要使用StrokeDashArrayand StrokeDashOffset,否则我只会使用一个Border将 BorderThickness 设置为"0,0,0,1"...的控件

感谢您的任何想法!

4

3 回答 3

10

为了详细说明kanchirk的回应,这对我有用:

<Path StrokeThickness="1"
 HorizontalAlignment="Stretch"  
 VerticalAlignment="Bottom"
 Data="M0,0 L1,0"
 Stretch="Fill"
 StrokeEndLineCap="Square"
 StrokeStartLineCap="Square"
 Stroke="Red"/> 

你也可以用 a 做同样的事情Line

<Line StrokeThickness="1" 
 HorizontalAlignment="Stretch"   
 VerticalAlignment="Bottom" 
 X2="1" 
 Stretch="Fill" 
 StrokeEndLineCap="Square" 
 StrokeStartLineCap="Square" 
 Stroke="Red"/>
于 2010-03-12T05:41:31.487 回答
1

我认为您需要像这样使用Path

<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 的必备品(目前)

于 2010-03-12T05:18:48.280 回答
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"/> 
于 2010-03-12T05:27:18.740 回答