Windows 8 AppBar涵盖了页面内容;我想要挤压

时间:2012-08-03 22:38:11

标签: xaml windows-runtime appbar

是否有一些技巧可以使WinRT中的Page.AppBars挤压/移动页面内容而不是覆盖内容的顶部?

1 个答案:

答案 0 :(得分:2)

你可以,但你需要编写一些代码才能做到。

我的版本使用视觉状态:

<Page.BottomAppBar>
    <AppBar
        x:Name="bottomAppBar"
        Opened="OnBottomAppBarOpened"
        Closed="OnBottomAppBarClosed">
        <StackPanel
            Orientation="Horizontal">
            <Button
                Style="{StaticResource PlayAppBarButtonStyle}" />
        </StackPanel>
    </AppBar>
</Page.BottomAppBar>
<Grid
    Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup
            x:Name="AppBarPushStates">
            <VisualState
                x:Name="AppBarClosed">
                <Storyboard>
                    <DoubleAnimation
                        Storyboard.TargetName="pushedContentTransform"
                        Storyboard.TargetProperty="Y"
                        To="0"
                        Duration="0:0:0.2">
                        <DoubleAnimation.EasingFunction>
                            <CubicEase
                                EasingMode="EaseOut" />
                        </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>
                </Storyboard>
            </VisualState>
            <VisualState
                x:Name="AppBarOpened">
                <Storyboard>
                    <DoubleAnimation
                        Storyboard.TargetName="pushedContentTransform"
                        Storyboard.TargetProperty="Y"
                        To="-88"
                        Duration="0:0:0.2">
                        <DoubleAnimation.EasingFunction>
                            <CubicEase
                                EasingMode="EaseOut" />
                        </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Border
        VerticalAlignment="Stretch"
        HorizontalAlignment="Stretch"
        BorderBrush="Orange"
        BorderThickness="5">
        <Border.RenderTransform>
            <TranslateTransform
                x:Name="pushedContentTransform" />
        </Border.RenderTransform>
        <TextBox
            TextWrapping="Wrap"
            Foreground="Brown"
            FontSize="48"
            Text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. Aenean nec lorem. In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend. Ut nonummy. Fusce aliquet pede non pede. Suspendisse dapibus lorem pellentesque magna. Integer nulla. Donec blandit feugiat ligula. Donec hendrerit, felis et imperdiet euismod, purus ipsum pretium metus, in lacinia nulla nisl eget sapien. Donec ut est in lectus consequat consequat." />
    </Border>
</Grid>

代码背后:

    private void OnBottomAppBarClosed(object sender, object e)
    {
        VisualStateManager.GoToState(this, "AppBarClosed", true);
    }

    private void OnBottomAppBarOpened(object sender, object e)
    {
        VisualStateManager.GoToState(this, "AppBarOpened", true);
    }