0

我目前有 XAML:

<Grid Name="WindowGrid">
    <Grid Height="66" HorizontalAlignment="Stretch" Margin="0" Name="ControlsGrid" VerticalAlignment="Bottom" Background="#B4000000" />
</Grid>

我想要的是当鼠标进入窗口(或者甚至是WindowGrid,最好是)时,ControlGrid 向上滑动,反之亦然(当光标离开时,它向下滑动)。我在 WPF/XAML 方面经验很少,在 WinForms 方面经验最多。我知道有一种方法可以使用故事板/触发器来做到这一点,但是我看到的例子太令人困惑了。

4

1 回答 1

2

使用事件触发器来执行此操作:

<Grid Name="WindowGrid">

    <Grid.Triggers>
        <EventTrigger RoutedEvent="MouseEnter">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation 
                        Storyboard.TargetName="ControlsGrid" 
                        Storyboard.TargetProperty="(Grid.Height)"
                        From="0" 
                        To="66" 
                        Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="MouseLeave">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation 
                        Storyboard.TargetName="ControlsGrid"
                        Storyboard.TargetProperty="(Grid.Height)"
                        From="66" 
                        To="0" 
                        Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>

    <!-- 
        This is a sample content to demostrate animation;
        Without it 'WindowGrid' will be collapsed.
    -->
    <ListBox />

    <Grid Margin="0" Name="ControlsGrid" VerticalAlignment="Bottom" Background="#B4000000" />
</Grid>
于 2012-06-04T06:16:33.043 回答