Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 当弹出窗口打开时,加载微调器挂起_Wpf_Animation_Popup_Spinner_Freeze - Fatal编程技术网

Wpf 当弹出窗口打开时,加载微调器挂起

Wpf 当弹出窗口打开时,加载微调器挂起,wpf,animation,popup,spinner,freeze,Wpf,Animation,Popup,Spinner,Freeze,我的WPF应用程序中有一个Apple Spinner用户控件。通过以下操作创建微调器。 我已将此微调器放置在弹出窗口中,并根据条件显示/隐藏。我正在使用MVVM和Prism 问题:我从“代码隐藏”中打开弹出窗口,微调器根本不动。它显示虽然(在弹出窗口中),但它是冻结的 若我从弹出窗口中删除微调器,动画工作正常,运行平稳 UC_SpinnerPopup.xaml代码 <UserControl x:Class="SEM.UI.Views.UC_SpinnerPopup" xm

我的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>
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; });
    }

查看型号代码喷丝头PopupViewModel.cs

<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>
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; });
    }
private bool\u打开;
受保护的只读IEventagegrator\u事件聚合器;
公共图书馆开放
{
得到
{
返回(u)打开;;
}
设置
{
SetProperty(参考打开,值);
}
}
公共SpinnerPopupViewModel(IEventAggregator事件聚合器)
{
这。_eventAggregator=eventAggregator;
这是.\u eventAggregator.GetEvent()
.Subscribe((项目)=>{ISSPoon=item;});
}
该属性是根据ViewModel中的条件设置的,并且在相同的条件下没有问题


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

问题是我们正在尝试在UI线程上加载数据,这肯定会导致此问题。为了获得显示UI进度条或微调器的预期结果,我们需要将这两个任务分开

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

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

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

您的EventTrigger/InvokeCommandAction应该做什么?老实说,我不知道为什么会这样写,但一旦我删除它,弹出窗口就不会出现。尝试检查联机资源以了解内容,但无法掌握任何内容。您没有绑定到命令,而是绑定到UserControl本身。尝试删除EventTrigger。由于没有执行任何操作,因此删除了该命令,然后只有微调器挂起并且在弹出窗口打开时不显示动画请提供完整但最小的问题回复,然后:您的EventTrigger/InvokeCommandAction应该做什么?老实说,我不知道为什么会编写此命令,但一旦我删除它,弹出窗口根本不显示。尝试检查联机资源以了解内容,但无法掌握任何内容。您没有绑定到命令,而是绑定到UserControl本身。尝试删除EventTrigger。由于没有执行任何操作,因此删除了该命令,然后只有微调器挂起并且在弹出OpenSplop时不显示动画请提供问题的完整但最小的回复,然后: