【发布时间】:2018-05-04 17:49:01
【问题描述】:
我的 WPF 应用程序中有一个 Apple Spinner 用户控件。通过关注link 创建的微调器。 我已将此 Spinner 放在弹出窗口中,并根据条件显示/隐藏。我正在使用 MVVM 和 Prism。
问题:我从后面的代码打开 Popup,但微调器根本没有动画。它虽然显示(在弹出窗口中),但它被冻结了。
如果我从弹出窗口中删除微调器,动画效果很好并且运行流畅。
UC_SpinnerPopup.xaml 代码:
<UserControl x:Class="SEM.UI.Views.UC_SpinnerPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SEM.UI.Views"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Interactivity;assembly=Microsoft.Practices.Prism.Interactivity"
mc:Ignorable="d"
Height="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}}"
Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}">
<Grid>
<Popup Name="SpinPopUp" HorizontalAlignment="Center" VerticalAlignment="Center" Width="500" Height="500"
Placement="Center" IsOpen="{Binding Path=IsSpinPopUpOpen, Mode=TwoWay}" AllowsTransparency="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Opened">
<prism:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource
AncestorType={x:Type UserControl}, Mode=FindAncestor}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid x:Name="LayoutRoot" Background="Transparent" >
<Grid Margin="100,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.15*"/>
</Grid.ColumnDefinitions>
<local:UC_AppleSpinner Margin="10" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="2"/>
</Grid>
</Grid>
</Popup>
</Grid>
查看模型代码SpinnerPopupViewModel.cs:
private bool _isSpinPopupOpen;
protected readonly IEventAggregator _eventAggregator;
public bool IsSpinPopUpOpen
{
get
{
return _isSpinPopupOpen;
}
set
{
SetProperty(ref _isSpinPopupOpen, value);
}
}
public SpinnerPopupViewModel(IEventAggregator eventAggregator)
{
this._eventAggregator = eventAggregator;
this._eventAggregator.GetEvent<SpinnerPopupEvent>()
.Subscribe((item) => { IsSpinPopUpOpen = item; });
}
该属性是根据ViewModel中的条件设置的,同样没有问题。
主要问题是 Popup 中的动画冻结。
【问题讨论】:
-
你的 EventTrigger/InvokeCommandAction 应该做什么?
-
老实说,我不知道为什么要写这个,但是一旦我删除它,弹出窗口就根本不显示。尝试查看在线资源以了解但无法掌握任何内容。
-
您不是绑定到命令,而是绑定到 UserControl 本身。尝试删除 EventTrigger 。
-
删除了命令,因为没有执行任何操作,然后只有微调器挂起并且在弹出窗口打开时没有动画
-
请提供您问题的完整但最少的回购:stackoverflow.com/help/mcve
标签: wpf animation popup spinner freeze