How to display a Progress Spinner (or other user interface) when the WPF ListView is a DataBound?

I have a WPF list view associated with a list of objects. One of the items displayed is a computed property (read-only, returns a string), which takes a small amount of time to calculate. When the window initially loads (or at any time when the user interface is updated with the Notify event), the user interface will freeze when data binding occurs. What I was interested in was a good mechanism to solve this problem (ideally, I would like to do something to align the screen with the counter and the text "Processing ..." or similar).

I thought I could do this by starting the start of the event with a database binding and releasing a story (or similar) and stopping the story when the end of the data binding event was completed, but I cannot find events of this nature.

Is there a recommended mechanism for working with long data bindings or for events I'm looking for, but I'm looking for the wrong location? Any help would be appreciated.

EDIT: I can get the rotation icon (Cursor.Wait) while the data is received and bound to the data (using the parts of the solution below), but now I need to know when the data binding is complete. The .Loaded event seems to fire when the control is placed on the screen (which happens immediately), but does not occur when the data is updated. It seems that there is no event like OnDataBoundCompleted for ListView, any ideas / thoughts on how to receive notifications when the data binding process is completed?

EDIT: Now, let's look at TargetUpdated, but get some odd results. If I put a message box in the event handler for TargetUpdated, then the user interface will be updated (ListView will display the data) and then a message box will appear. If I cut out the message box and just had a variable parameter (i.e.IsBusyCursor = Cursors.Arrow), it does this before the ListView displays the data.

** : ** Cursor = Wait, , ListView, ( ) , ListView Stet Cursor = Arrow. , , DataBinding Completed ( - , , ), .

+3
3

Cursor = Wait, , ListView, ( ), , ListView stet Cursor = Arrow.

, , DataBinding Completed ( , ), , , .

0

ChrisHDog. MVVM, , :

-, ViewModel , IsBusy:

public bool IsBusy
{
   get { return _isBusy; }
   set
   {
      _isBusy = value;
      NotifyPropertyChanged("IsBusy");
   }
}

, , . , , IsBusy true. XAML :

<UserControl x:Class="UserControls.Views.AgentListView"
             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:Converters="clr-namespace:UserControls.Utility.Converters" 
             xmlns:Controls="clr-namespace:UserControls.Controls" 
             xmlns:DependencyProperties="clr-namespace:UserControls.DependencyProperties" 
             Cursor="{Binding IsBusy, Converter={Converters:CursorExtensionConverter}}" >

CursorExtensionConverter - IValueConverter Cursor, XAML:

namespace UserControls.Utility.Converters
{
  public class CursorExtensionConverter : MarkupExtension, IValueConverter
  {
    private static CursorExtensionConverter instance = new CursorExtensionConverter();

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      if (value != null && ((bool) value))
        return Cursors.Wait;
      else
        return Cursors.Arrow;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      throw new NotImplementedException();
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
      return instance;
    }

  }
}

, , IsBusy false. .

, , , . Action async BeginInvoke, , , : http://www.wintellect.com/CS/blogs/jlikness/archive/2009/12/16/dispatching-in-silverlight.aspx.

, !

+5

, BackgroundWorker , .

Essentially, you will have a function that displays the Wait control and then uses BackgroundWorker to perform long-term calculation in another thread. When the calculation is complete, another event occurs that says BackgroundWorker is complete, and you can hide the Wait element and bind the data. If you wish, you can report on the progress in the calculation, if possible.

+1
source

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


All Articles