2011-04-26 66 views
3

這(有希望)是一個簡單的...我試圖找到一個WPF面板,我可以使用它時,調整大小保持所有的垂直對齊的兒童(按鈕)偏離面板的底部邊緣相同的距離,所以看起來他們正在擴大。什麼WPF面板控件使用錨點兒童邊緣(六角琴效果)?

顯而易見的是使用一個停靠面板和底部的錨點,但這似乎並不奏效。讓更多的2個孩子在那裏弄亂隊列和我做的任何事情,我不能讓他們垂直排隊。我嘗試了各種面板,但沒有喜悅。我假設它非常簡單,但它難倒了我!

基本上我試圖得到一個手風琴效果,當我點擊面板擴展的頂部按鈕並顯示所有的子按鈕。當我再次點擊頂部按鈕時,它會崩潰。我想我可以用故事板移動每個孩子,但我必須認爲我所有的故事需要做的是改變面板的尺寸,並讓孩子們保持他們的偏移量和六角琴出...

任何想法?

在此先感謝!

回答

1

我相信你實際上可以使用Canvas並設置控件的Canvas.Top,Left,Right和Bottom屬性來獲得與WinForms和anchor相同的效果。

<Canvas> 
    <Button Canvas.Left="30" Canvas.Bottom="10" Content="Button 1" Name="button1" /> 
    <Button Canvas.Left="90" Canvas.Bottom="10" Content="Button 2" Name="button2" /> 
</Canvas> 

enter image description here

而且網格可以做類似:

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
     <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="40" /> 
    </Grid.RowDefinitions> 
    <Button Grid.Row="1" Grid.Column="0" Content="Button 1" Name="button1" Margin="5" /> 
    <Button Grid.Row="1" Grid.Column="1" Content="Button 2" Name="button2" Margin="5" /> 
</Grid> 
1

如果「基本上我試圖讓手風琴效應」是你的問題的本質(我說得對不對?)那麼,你是否嘗試過使用內置的WPF擴展器?在我看來,你正在試圖建立自己的...

0

我不完全明白你的意思是由六角琴效應,它可能與伸展以及。如果你想錨定你可以使用Grid:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition /> <!-- Gets all available space i.e. resizes with window --> 
     <RowDefinition Height="Auto"/> <!-- Sizes to content, always stays at the bottom --> 
    </Grid.RowDefinitions> 
    <!-- Resizable content goes in Grid.Row="0" --> 
    <StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="5"> 
     <Button Name="ButtonOK" HorizontalAlignment="Right" Width="100" Margin="5" Click="ButtonOK_Click" IsDefault="True">OK</Button> 
     <Button Name="ButtonCancel" HorizontalAlignment="Right" Width="100" Margin="5" Click="ButtonCancel_Click" IsCancel="True">Cancel</Button> 
    </StackPanel> 
</Grid>