2011-07-20 35 views
0

我有以下XAML顯示文本塊的堆棧面板。由於我的主網格大小,堆疊面板中的最後幾個項目自然會被裁剪掉。但是,如果我將堆疊面板的父網格(不是主網格)垂直向上翻譯,堆疊面板的內容仍然會被剪切,而不是顯示底部的項目。我如何在網格上執行垂直翻譯而不剪切堆棧面板的底部內容?防止在垂直翻譯時WPF剪切網格內容

視圖框很重要 - 因爲第一個網格需要將自己的大小設置爲主窗口或顯示器的最大高度。

<Window x:Class="WpfApplication5.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow"> 
    <Viewbox> 
     <Grid Width="500" Height="888" Background="#cccccc"> 
      <Grid Background="#cc99cc"> 
       <Grid.RenderTransform> 
        <TranslateTransform Y="-800"/> 
       </Grid.RenderTransform> 
       <StackPanel> 
        <TextBlock Text="This is a test 1" FontSize="50" Foreground="Blue"/> 
        <TextBlock Text="This is a test 2" FontSize="50" Foreground="Red"/> 
        <TextBlock Text="This is a test 3" FontSize="50" Foreground="Green"/> 
        <TextBlock Text="This is a test 4" FontSize="50" Foreground="Orange"/> 
        <TextBlock Text="This is a test 5" FontSize="50" Foreground="Yellow"/> 
        <TextBlock Text="This is a test 6" FontSize="50" Foreground="Purple"/> 
        <TextBlock Text="This is a test 7" FontSize="50" Foreground="Blue"/> 
        <TextBlock Text="This is a test 8" FontSize="50" Foreground="Red"/> 
        <TextBlock Text="This is a test 9" FontSize="50" Foreground="Green"/> 
        <TextBlock Text="This is a test 10" FontSize="50" Foreground="Orange"/> 
        <TextBlock Text="This is a test 11" FontSize="50" Foreground="Yellow"/> 
        <TextBlock Text="This is a test 12" FontSize="50" Foreground="Purple"/> 
        <TextBlock Text="This is a test 13" FontSize="50" Foreground="Blue"/> 
        <TextBlock Text="This is a test 14" FontSize="50" Foreground="Red"/> 
        <TextBlock Text="This is a test 15" FontSize="50" Foreground="Green"/> 
        <TextBlock Text="This is a test 16" FontSize="50" Foreground="Orange"/> 
       </StackPanel> 
      </Grid> 
     </Grid> 
    </Viewbox> 
</Window> 

回答

1

只需取出網格上的高度屬性即可。

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     x:Name="Wind1" 
     Title="MainWindow"> 
    <Viewbox> 
     <Grid Width="500" Background="#cccccc"> 
      <Grid Background="#cc99cc"> 
       <Grid.RenderTransform> 
        <TranslateTransform Y="-800"/> 
       </Grid.RenderTransform> 
       <StackPanel x:Name="stack1"> 
        <TextBlock Text="This is a test 1" FontSize="50" Foreground="Blue"/> 
        <TextBlock Text="This is a test 2" FontSize="50" Foreground="Red"/> 
        <TextBlock Text="This is a test 3" FontSize="50" Foreground="Green"/> 
        <TextBlock Text="This is a test 4" FontSize="50" Foreground="Orange"/> 
        <TextBlock Text="This is a test 5" FontSize="50" Foreground="Yellow"/> 
        <TextBlock Text="This is a test 6" FontSize="50" Foreground="Purple"/> 
        <TextBlock Text="This is a test 7" FontSize="50" Foreground="Blue"/> 
        <TextBlock Text="This is a test 8" FontSize="50" Foreground="Red"/> 
        <TextBlock Text="This is a test 9" FontSize="50" Foreground="Green"/> 
        <TextBlock Text="This is a test 10" FontSize="50" Foreground="Orange"/> 
        <TextBlock Text="This is a test 11" FontSize="50" Foreground="Yellow"/> 
        <TextBlock Text="This is a test 12" FontSize="50" Foreground="Purple"/> 
        <TextBlock Text="This is a test 13" FontSize="50" Foreground="Blue"/> 
        <TextBlock Text="This is a test 14" FontSize="50" Foreground="Red"/> 
        <TextBlock Text="This is a test 15" FontSize="50" Foreground="Green"/> 
        <TextBlock Text="This is a test 16" FontSize="50" Foreground="Orange"/> 
       </StackPanel> 
      </Grid> 
     </Grid> 
    </Viewbox> 
</Window>