0

I am having problems with visibility of the spinner control. The control itself works... If I set it to visible right after Initialize it shows and animates as expected.

But if I try to show it from the code it never gets drawn...

the .cs file (presenter)

private void SaveDocument(Document aDocument)
{
  if (AllowFlag != null)
  {
    this.View.ShowDocumentProgressSpinner(true);
    this.Save(aDocument);
    this.View.ShowDocumentProgressSpinner(false);
  }
}

the xaml.cs file

void IDocumentView.ShowDocumentProgressSpinner(bool show)
{
  if (show)
  {
    this.DocumentProgressSpinner.Visibility = Visibility.Visible;
  }
  else
  {
    this.DocumentProgressSpinner.Visibility = Visibility.Hidden;
  }
}

If i set the visibility to visible right after initialize the spinner works!

part of the xaml of the main control (the spinner is custom control)

...
      <Viewbox Grid.Row="3" Width="30" Height="30"
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
        <my:DocumentProgressSpinnerView x:Name="DocumentProgressSpinner" />
...

Probably another threading problem, but I have also tried:

Thread.CurrentThread == Dispatcher.CurrentDispatcher.Thread

TRUE

Dispatcher.FromThread(Thread.CurrentThread).CheckAccess()

TRUE

The control gets invoked, because the "windows spinner" gets activated, just the control never gets shown...

no9
  • 6,424
  • 25
  • 76
  • 115

1 Answers1

2

The problem is that you are running your save operation on the dispatcher thread and during the save operation the dispatch thread is blocked the whole time. It's only after your save operation has finished that the UI is updated and thus you will never see the "waiting" state. Instead you should spin off a new thread and from within the event dispatch and set the wait indicator to visible. In the separate thread perform the save operation and once the saving is done, use the dispatcher to hide the wait indicator again on the Dispatcher thread.

See this answer for more details on how to implement this.

Community
  • 1
  • 1
Sebastian
  • 7,729
  • 2
  • 37
  • 69
  • what if the Save method performs some UI updates ... wouldnt running it in bckWorker prevent it to update UI thread - GUI? – no9 Dec 23 '13 at 10:11
  • The UI updates need to be done through the Dispatcher. You can (and need to) do multiple asynchronous Dispatcher.Invoke(...) calls from within the "Save-Thread". – Sebastian Dec 23 '13 at 10:31