Download WPF Animations

I have a ListView with many items that need to be loaded in the search. And I would like to provide the user with a richer user interface so that a spinning circle (known from the expected AJAX) is displayed when loading .

I understand that I will have to go to Threads or something like that, but since I have never done this before in WPF, I'm sure there is something better than Threads in WPF (or Simpe BackgroundWorker).

In any case, you need to display this animation at boot time. Any ideas? Thanks!

+3
source share
2 answers

.

UserControl, . - XAML : <customControls:LoadingAnimation x:Name="LoadingAnimation" />. ,

LoadingAnimation.Show();

, , , BeginInvoke(), .

, , LoadingAnimation.Hide(). ! :

private void SearchClick(object sender, RoutedEventArgs e)
{
     LoadingAnimation.Show();

     new StringDelegate(DoSearch).BeginInvoke("TextToSearch", null, null);
}

private void DoSearch(string searchText)
{
    object result = /* Do the time consuming work */    

    Dispatcher.BeginInvoke(DispatcherPriority.Normal,
         new ResultDelagate(UpdateUserInterface), result);
}

private void UpdateUserInterface(object result)
{
    LoadingAnimation.Hide();            

    DataContext = result as /* what you want */;
}
+2

Source: https://habr.com/ru/post/1713824/


All Articles