предотвратить WPF-отсечение содержимого Grid при вертикальной трансляции - PullRequest
0 голосов
/ 21 июля 2011

У меня есть следующий XAML, который отображает панель стека текстовых блоков.Из-за моего основного размера сетки последние несколько элементов на панели стека естественным образом обрезаются.Однако, если я перевожу родительскую сетку панели стека (а не основную сетку) вертикально вверх, содержимое панели стека все равно будет обрезано вместо отображения элементов внизу.Как я могу выполнить вертикальный перевод на сетке, не обрезая нижнее содержимое панели стека?

Важно окно просмотра - поскольку первая сетка должна масштабироваться до максимальной высоты основного окна или монитора.

<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 Ответ

1 голос
/ 14 июля 2012

Просто удалите свойство Высота из сетки.

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...