2014-10-06 69 views
1

我必须填写我的窗口有三个可调Rectangles喜欢:动态矩形高度

enter image description here

<Grid x:Name="FileDragAndDrop" Grid.Row="0" Grid.RowSpan="2" Background="Aqua"> 
    <Rectangle Fill="Beige" HorizontalAlignment="Stretch" Height="110" Stroke="Black" VerticalAlignment="Top" /> 
    <Rectangle Fill="Aquamarine" HorizontalAlignment="Stretch" Height="110" Stroke="Black" VerticalAlignment="Center" /> 
    <Rectangle Fill="BlanchedAlmond" HorizontalAlignment="Stretch" Height="110" Stroke="Black" VerticalAlignment="Bottom" /> 
</Grid> 

但上面的代码做这个:

enter image description here

我试过Height="2*"following the answer),但它给出错误

“2 *”字符串不能转换为长

我怎样才能解决这个错误,使他们的高度动态?是否可以用xaml或者我必须在C#中完成?

回答

1

如果您不能将矩形放入主网格的行中,则可以使用嵌套网格和Grid.RowSpan覆盖整个主网格上的嵌套网格。

<Grid x:Name="FileDragAndDrop" Grid.Row="0" Grid.RowSpan="2" Background="Aqua"> 
    <Grid.RowDefinitions> 
     <!-- suppose you have 3 RowDefinitions here --> 
    </Grid.RowDefinitions> 
    <Grid Grid.RowSpan="3"> 
    <Grid.RowDefinitions> 
     <RowDefinition MinHeight="110"/> 
     <RowDefinition MinHeight="110"/> 
     <RowDefinition MinHeight="110"/> 
    </Grid.RowDefinitions/> 
    <Rectangle Fill="Beige" Stroke="Black"/> 
    <Rectangle Fill="Aquamarine" Stroke="Black" Grid.Row="1"/> 
    <Rectangle Fill="BlanchedAlmond" Stroke="Black" Grid.Row="2"/> 
    </Grid> 
</Grid> 
+0

好吧!已经有太多的行。没有其他办法吗? – Shaharyar 2014-10-06 20:18:10

+0

@Shaharyar,所以你想让3个rects覆盖整个网格吗? – 2014-10-06 20:21:03

+0

是的。但他们应该等于 – Shaharyar 2014-10-06 20:22:06