加载微调器在弹出窗口打开时挂起



我的WPF应用程序中有一个Apple Spinner用户控件。通过以下链接创建的微调器。 我已将此微调器放置在弹出窗口中并根据条件显示/隐藏。我正在使用MVVM和Prism。

问题:我从代码隐藏打开弹出窗口,微调器根本没有动画。它显示虽然(在弹出窗口中(,但它被冻结了。

如果我从弹出窗口中删除微调器,动画工作正常且运行流畅。

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>

查看模型代码微调器弹出视图模型.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; });
}

该属性是根据视图模型中的条件设置的,并且没有问题。

主要问题是弹出窗口中的动画冻结。

问题是我们试图在 UI 线程上加载数据,这肯定会带来这个问题。为了达到显示 UI 进度条或微调器的预期结果,我们需要将这两个任务分开。

将数据/加载数据放在一个线程上并分离 UI。 有很多文章和问题,深入讨论了这些细节。