2012-04-24 63 views
3

我有一個4列的網格。在第一列是一個ZIndex爲99的畫布,裏面是一個擴展器。展開方向設置爲右。當我點擊標題時,擴展器擴展了第2列的OVER TOP ...這正是我想要的。我試圖在第4列內複製這個(只有相反的方向),這樣當展開時,它會顯示在第3列上。儘管我已經將第二個擴展器的ExpandDirection標記爲「Left」,但它仍然展開爲正確的,並在屏幕之外。WPF Expander在Canvas內部不會向左擴展

這裏是工作的擴展:

<Canvas Grid.Column="0" Panel.ZIndex="99" Grid.RowSpan="4" VerticalAlignment="Stretch" Margin="0,5"> 
    <Expander ExpandDirection="Right" Style="{DynamicResource OptionsExpanderStyle}" VerticalAlignment="Stretch" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}"> 
     <Border BorderBrush="Black" BorderThickness="0,0,2,0"> 
      <Grid Background="White"> 

      </Grid> 
     </Border> 
    </Expander> 
</Canvas> 

這裏是破擴展:

<Canvas x:Name="rightCanvas" Panel.ZIndex="99" Grid.RowSpan="4" Grid.Column="3" Margin="0,5"> 
    <Expander ExpandDirection="Left" Style="{DynamicResource OptionsExpanderStyle}" HorizontalAlignment="Right" VerticalAlignment="Stretch" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}"> 
     <Border BorderBrush="Black" BorderThickness="2,0,0,0"> 
      <Grid Background="White" Width="150"> 

      </Grid> 
     </Border> 
    </Expander> 
</Canvas> 
+0

爲什麼用帆布? – 2012-04-24 14:38:45

+0

@NicolasRepiquet,它是我發現的唯一方法,允許我擴展第2和第3列中的其他控件。還有其他方法可以做到這一點嗎?簡單地將ZIndex放在擴展器上不起作用。 – Thelonias 2012-04-24 15:00:01

回答

3

不要使用畫布。

嘗試類似的東西:

<Grid> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition/> 
      <ColumnDefinition/> 
     </Grid.ColumnDefinitions> 
     <TextBlock Background="LightBlue" 
      TextAlignment="Center" Text="Left Column"/> 
     <TextBlock Grid.Column="1" Background="LightCoral" 
      TextAlignment="Center" Text="Right Column"/> 
    </Grid> 
    <Expander Background="LightGray" ExpandDirection="Right" 
     Header="LeftMenu" VerticalAlignment="Top" HorizontalAlignment="Left"> 
     <StackPanel Width="200"> 
      <TextBlock Text="Some menu stuff"/> 
      <TextBlock Text="Some more"/> 
     </StackPanel> 
    </Expander> 
    <Expander Background="LightGray" ExpandDirection="Left" 
     Header="RightMenu" VerticalAlignment="Top" HorizontalAlignment="Right"> 
     <StackPanel Width="200" > 
      <TextBlock Text="Some menu stuff"/> 
      <TextBlock Text="Some more"/> 
     </StackPanel> 
    </Expander> 
</Grid> 
+0

我同意。擴展器正確擴展,但在父 - >畫布內移動。 – 2012-04-24 15:18:35

+1

你真的應該擺脫所有這些畫布:D – 2012-04-24 15:25:08

+1

有人可以解釋爲什麼我不應該使用畫布(除了它不適合我的事實)。我正在執行上面的答案,但我只是好奇人們爲什麼說我不應該使用畫布。 – Thelonias 2012-04-24 15:34:53