0

我是使用 WPF 故事板的新手,这是我的代码:

   <StackPanel>

    <Border Grid.Row="0" Background="Black" Height="40" Name="Border1"></Border>

    <Grid Height="0" Name="MyGrid" Background="Green">
        <Grid.Triggers>
            <EventTrigger RoutedEvent="UserControl.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="MyGrid" 
                    Storyboard.TargetProperty="Height" From="0" To="40" 
                    Duration="0:0:1" BeginTime="0:0:0"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
    </Grid>

</StackPanel>

我想将触发情节提要开始的事件更改为 Border1.MouseEnter。

这可能吗?

谢谢

4

2 回答 2

1

在这种情况下,您应该将触发器移动到 Border 控件:

<StackPanel>

<Border Grid.Row="0" Background="Black" Height="40" Name="Border1">
   <Border.Triggers>
        <EventTrigger RoutedEvent="Border.MouseEnter">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="MyGrid" 
                       Storyboard.TargetProperty="Height" From="0" To="40" 
                       Duration="0:0:1" BeginTime="0:0:0"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Border.Triggers>
</Border>

<Grid Height="0" Name="MyGrid" Background="Green">

</Grid>

于 2012-11-02T12:21:39.390 回答
0

我真的没有尝试过,但这应该有效:

<StackPanel>
<StackPanel.Triggers>
    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="Border1">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation Storyboard.TargetName="MyGrid" 
                    Storyboard.TargetProperty="Height" From="0" To="40" 
                    Duration="0:0:1" BeginTime="0:0:0"/>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</StackPanel.Triggers>
        <Border Grid.Row="0" Background="Black" Height="40" Name="Border1"></Border>
        <Grid Height="0" x:Name="MyGrid" Background="Green" VerticalAlignment="Bottom"/>
</StackPanel>
于 2012-11-02T12:26:44.133 回答