Browse Source

Add Title properties for dialog viewmodel bases

pull/333/head
Ionite 12 months ago
parent
commit
3f79a6e719
No known key found for this signature in database
  1. 22
      StabilityMatrix.Avalonia/ViewModels/Base/ContentDialogViewModelBase.cs
  2. 10
      StabilityMatrix.Avalonia/ViewModels/Base/TaskDialogViewModelBase.cs

22
StabilityMatrix.Avalonia/ViewModels/Base/ContentDialogViewModelBase.cs

@ -1,27 +1,43 @@
using System;
using Avalonia.Threading;
using FluentAvalonia.UI.Controls;
using StabilityMatrix.Avalonia.Controls;
namespace StabilityMatrix.Avalonia.ViewModels.Base;
public class ContentDialogViewModelBase : ViewModelBase
{
public virtual string? Title { get; set; }
// Events for button clicks
public event EventHandler<ContentDialogResult>? PrimaryButtonClick;
public event EventHandler<ContentDialogResult>? SecondaryButtonClick;
public event EventHandler<ContentDialogResult>? CloseButtonClick;
public virtual void OnPrimaryButtonClick()
{
PrimaryButtonClick?.Invoke(this, ContentDialogResult.Primary);
}
public virtual void OnSecondaryButtonClick()
{
SecondaryButtonClick?.Invoke(this, ContentDialogResult.Secondary);
}
public virtual void OnCloseButtonClick()
{
CloseButtonClick?.Invoke(this, ContentDialogResult.None);
}
/// <summary>
/// Return a <see cref="BetterContentDialog"/> that uses this view model as its content
/// </summary>
public virtual BetterContentDialog GetDialog()
{
Dispatcher.UIThread.VerifyAccess();
var dialog = new BetterContentDialog { Title = Title, Content = this };
return dialog;
}
}

10
StabilityMatrix.Avalonia/ViewModels/Base/TaskDialogViewModelBase.cs

@ -1,6 +1,7 @@
using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Threading;
using AvaloniaEdit.Rendering;
using FluentAvalonia.UI.Controls;
using StabilityMatrix.Avalonia.Languages;
@ -13,6 +14,8 @@ public abstract class TaskDialogViewModelBase : ViewModelBase
{
private TaskDialog? dialog;
public virtual string? Title { get; set; }
protected static TaskDialogCommand GetCommandButton(string text, ICommand command)
{
return new TaskDialogCommand
@ -27,11 +30,7 @@ public abstract class TaskDialogViewModelBase : ViewModelBase
protected static TaskDialogButton GetCloseButton()
{
return new TaskDialogButton
{
Text = Resources.Action_Close,
DialogResult = TaskDialogStandardResult.Close
};
return new TaskDialogButton { Text = Resources.Action_Close, DialogResult = TaskDialogStandardResult.Close };
}
/// <summary>
@ -43,6 +42,7 @@ public abstract class TaskDialogViewModelBase : ViewModelBase
dialog = new TaskDialog
{
Header = Title,
Content = this,
XamlRoot = App.VisualRoot,
Buttons = { GetCloseButton() }

Loading…
Cancel
Save