gpt4 book ai didi

WPF Popup事件处理-打开Popup时如何触发

转载 作者:行者123 更新时间:2023-12-04 17:58:27 25 4
gpt4 key购买 nike

我创建了一个WPF弹出窗口,其中包含带有边框的网格。
每次打开弹出窗口时,我都希望触发与边框相关的某些动画。

目前的代码是这样的

<Popup x:Name="myPopUp" >
<Border x:Name="myBorder" >
<Border.Triggers>
<EventTrigger RoutedEvent="Popup.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="myBorder"
Storyboard.TargetProperty="Height"
From="10" To="255" Duration="0:0:0.20" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
<Grid />
</Border>
</Popup>

根据代码,边框将在弹出窗口第一次打开时显示动画。
每次打开弹出窗口时,我需要进行哪些更改以触发边框动画?

最佳答案

根据这里给出的建议,现在有点过期了(我一年前问过这个问题:)),我可以找出解决方案。

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" >
<Window.Resources>
<Style x:Key="popupStyle" TargetType="{x:Type Popup}" >
<Style.Triggers>
<Trigger Property="IsOpen" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Height"
From="10" To="255" Duration="0:0:0.20" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Button Width="100" Height="100" Click="Button_Click"></Button>
<Popup Name="popUp" Width="100" Height="100" Style="{StaticResource popupStyle}" >
<Border x:Name="myBorder" Background="Blue"/>
</Popup>
</Grid>

和后面的示例代码触发弹出窗口。
    private void Button_Click(object sender, RoutedEventArgs e)
{
popUp.PlacementTarget = (Button)sender;
popUp.IsOpen = true;
}

尽管我只能为弹出窗口设置动画,而不能为此处的边框设置动画,但是它几乎可以提供相同的效果。

关于WPF Popup事件处理-打开Popup时如何触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3668303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com