Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

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.

...

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

Create the AntonyView with IConfigurationViewModel

As antony cannot guess your ViewModel in a goo way, you need to pass it explicit to the AntonyView. Therefore you can use the static Method AntonyView.FromWpfFrameworkElement. In the second parameter you can pass the ViewModel. The snippet shows an AdministratorMenuNode as an example.

Code Block
public class MyConfigurationAdminMenuNode: AdministratorMenuNode
{
    public MyConfigurationAdminMenuNode(Func<MyConfigurationViewModel> createViewModel)
    {
        Identifier = "MyConfigurationName";
        ParentIdentifier = "MyConfigurationParent";
        DisplayName = "MyConfiguration";
        ImageAsSvg = Resources.my_configuration;
        GenerateViewAsync = async reporter =>
        {
            reporter.ReportStatus("Lade Daten");

            BrowserTabConfigurationView view = new MyConfigurationView();
            BrowserTabConfigurationViewModel viewModel = createViewModel.Invoke();

            return AntonyView.FromWpfFrameworkElement(view, viewModel);
        };
    }
}

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. To use it, simply create it within the constructor and pass the base object to track (this). The object needs to be a INotifyPropertyChanged to work correctly. The tracker will track all Properties with are annotated with the [DirtyTrack] attribute.

Note

Members are not tracked by the IsDirtyTracker !

Info

You can mark your ObservableCollection<T> with the DirtyTrack attribute. In this case the IsDirtyTracker will automatically track the Collection and every Element within the array automatically.

Code Block
languagec#
public class MyConfigurationViewModel : INotifyPropertyChanged, IConfigurationViewModel
{
  public MyConfigurationViewModel()
  {
    StateTracker = new IsDirtyChangeTracker(this);
  }
  
  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
}

Conclusion

It is quite easy to track your ViewModel for changes and to give this information to antony. So it’s up to you to implement this feature for your customter.