我是使用WPF Storyboards的新手,这是我的代码:
<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。
这可能吗?
感谢名单
答案 0 :(得分: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>
答案 1 :(得分: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>