2012-06-07 33 views
0

我有以下佈局如何強制元素溢出網格內它

<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <Grid Height="100" Background="Wheat" Opacity="0.4"> 
     <StackPanel Orientation="Vertical" VerticalAlignment="Bottom"> 
      <Slider Orientation="Vertical" Height="170" HorizontalAlignment="Center" Background="White" /> 
      <Button Content="Btn" Width="100"/> 
     </StackPanel> 
    </Grid> 
</Grid> 

在這種情況下電網將剪輯滑塊,溢出電網的其餘部分。 所以我越來越喜歡這個 enter image description here 結果,而我想造成這樣 enter image description here 所以,我怎麼能強迫滑塊溢出電網無剪輯?這是否有其他解決方案? 事實上,我有更復雜的佈局,所以現在歡迎使用Canvas而不是Grid。

+0

您是否需要外部'Grid'(「LayoutRoot」),除非您需要另外一個網格,否則您最好將其更改爲'DockPanel'。 – CodingGorilla

回答

0

您可以使用單個Grid並與其兒童的Grid.RowSpanGrid.ColumnSpan屬性一起玩。

<Grid x:Name="LayoutRoot" 
     Background="Transparent"> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="Auto" /> 
    <RowDefinition Height="Auto" /> 
    <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="*" /> 
    <ColumnDefinition Width="Auto" /> 
    <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 

    <Rectangle Grid.Row="2" 
      Grid.Column="0" 
      Grid.ColumnSpan="3" 
      Height="100" 
      Fill="Wheat" 
      Opacity="0.4" /> 

    <StackPanel Grid.Row="1" 
       Grid.RowSpan="2" 
       Grid.Column="1"> 
    <Slider Orientation="Vertical" 
      Height="170" 
      HorizontalAlignment="Center" 
      Background="White" /> 
    <Button Content="Btn" 
      Width="100" /> 
    </StackPanel> 
</Grid> 
+0

我不能有單個網格,但使用你的例子我重建了我的佈局。 –