我的WPF应用程序中有一个Apple Spinner用户控件。通过跟随link创建的微调器。 我把这个Spinner放在Popup中并根据条件显示/隐藏。我正在使用MVVM和Prism。
问题:我从代码后面打开Popup,而spinner根本没有动画。它虽然显示(在Popup中),但它被冻结。
如果我从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中冻结动画。
答案 0 :(得分:0)
问题是我们正在尝试在UI线程上加载数据,这肯定会给出这个问题。为了实现显示UI进度条或微调器的预期结果,我们需要将两个任务分开。
将数据/加载数据放在一个线程上并分离UI。 有很多文章和问题,深入讨论这些细节。