1

I have an Apple Spinner User Control in my WPF application. Spinner created by following link. I have placed this Spinner in a Popup and show/hide based on condition. I am using MVVM and Prism.

Issue : I open Popup from code behind, and spinner does not animate at all. It shows though (within Popup), but it is frozen.

In case I remove spinner from Popup, animation works fine and runs smoothly.

The UC_SpinnerPopup.xaml code:

<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>

View Model code 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; });
    }

The property is set based on condition in ViewModel and there is no issue in the same.

Main issue is freezing of animation within Popup.

Incredible
  • 3,495
  • 8
  • 49
  • 77
  • What is your EventTrigger/InvokeCommandAction supposed to do? – mm8 Aug 10 '17 at 10:07
  • Honestly, I have no idea, why this is written, but as soon as I remove it, the popup doesn't show up at all. Tried checking online resources to understand but unable to grasp anything. – Incredible Aug 10 '17 at 11:57
  • You are not binding to a command but the UserControl itself. Try to remove the EventTrigger . – mm8 Aug 10 '17 at 11:59
  • Removed the command as there was no action being performed, then only the spinner hangs and doesnot animate when popup opens – Incredible Aug 11 '17 at 06:27
  • Please provide a full but minimal repo of your issue then: https://stackoverflow.com/help/mcve – mm8 Aug 11 '17 at 08:19
  • https://stackoverflow.com/questions/38040412/animaitons-storyboards-in-wpf-stop-when-ui-thread-is-busy following this suggestion, seems like problem is similar. – Incredible Aug 11 '17 at 08:36

1 Answers1

0

The issue is we are trying to load data on the UI thread, which will definitely give this issue. In order to achieve the desired result of showing the UI progress bar or spinner, we need to separate both the tasks.

Bring data/load data on one thread and separate the UI. There are bunch of articles and questions, which discuss these details in depth.

Incredible
  • 3,495
  • 8
  • 49
  • 77