我有以下XAML显示文本块的堆栈面板。由于我的主网格大小,堆栈面板中的最后几个项目自然会被剪裁。但是,如果我垂直向上翻译堆栈面板的父网格(而不是主网格),堆栈面板的内容仍然会被剪切而不是显示底部的项目。如何在不剪切堆栈面板底部内容的情况下在网格上执行垂直平移?
Viewbox很重要 - 因为第一个网格需要将自身大小调整为主窗口或监视器的最大高度。
<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>
答案 0 :(得分: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>