Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

General

A common task within your module might be the configuration. Saving and reading of the configuration can be done be following the guide here Howto use antonys configuration systen. But within the configuration pages (within the admin, client or antonyhub) the user can navigate away from your page, without saving the changes. In this case you should ask if the user wants to save the changes.

But as the AntonyView only provides a FrameworkElement (or WinForms) you cannot detect that the user navigates away. You also cannot use internal Events like Unload as this event is also called if the user changes the session. To solve the issue antony provides an extra interface for it. The IConfigurationViewModel

Tl;Dr;

  1. Let your ViewModel implement the IConfigurationViewModel Interface and implement it

  2. Pass the ViewModel in the AntonyView.FromWpfFrameworkElement as the 2nd parameter.

  3. Deploy

The IConfigurationViewModel Interface

This interface is specially designed for the given task and only has a few methods. The IsDirty Property is called by antony, if the user navigates away. If you return a dirty state, antony will ask the if the changes should be saved. If he decides to save, the Save method is called.

The OnClose Method will be called, if you provided a IConfigurationViewMOdel independent if your ViewModel ist dirty or not.

Implementing IConfigurationViewModel Example

If you are a module developer for antony you will get access to the assembly antony.groupware.wpf via our nuget feed. We recommend to use the IsDirtyTracker

public class MyConfigurationViewModel : INotifyPropertyChanged, IConfigurationViewModel
{

  public IsDirtyChangeTracker StateTracker { get; set; }
  public DirtyState IsDirty => StateTracker.DirtyState; 
  public void OnClose() => StateTracker.Dispose();
  public void Save(IProgressReporter reporter)
  {
    DoSaveLogicHere();
    StateTracker.IsDirty = false; // this will prevent double asking the user
  }
  
#region Property string TestProperty
  private string _TestProperty;
  [DirtyTrack]
  public string TestProperty { get => _TestProperty; set { if (value == _TestProperty) return; _TestProperty = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TestProperty))); } }
#endregion
}
  • No labels