【问题标题】:prevent WPF clipping of Grid content when translated vertically垂直翻译时防止 WPF 裁剪网格内容
【发布时间】:2012-07-14 08:54:32
【问题描述】:

我有以下显示文本块堆栈面板的 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>

【问题讨论】:

    标签: wpf xaml


    【解决方案1】:

    只需取出 Grid 上的 Height 属性即可。

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-06
      • 1970-01-01
      • 2015-06-21
      • 2017-09-04
      相关资源
      最近更新 更多