From 3f79a6e71908904a183f641d45447e0b6a2d63fa Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 4 Dec 2023 17:59:58 -0500 Subject: [PATCH] Add Title properties for dialog viewmodel bases --- .../Base/ContentDialogViewModelBase.cs | 22 ++++++++++++++++--- .../Base/TaskDialogViewModelBase.cs | 10 ++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/ContentDialogViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/ContentDialogViewModelBase.cs index c82b6721..457267ad 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/ContentDialogViewModelBase.cs +++ b/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? PrimaryButtonClick; public event EventHandler? SecondaryButtonClick; public event EventHandler? 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); } + + /// + /// Return a that uses this view model as its content + /// + public virtual BetterContentDialog GetDialog() + { + Dispatcher.UIThread.VerifyAccess(); + + var dialog = new BetterContentDialog { Title = Title, Content = this }; + + return dialog; + } } diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/TaskDialogViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/TaskDialogViewModelBase.cs index 6825c12e..a09db95d 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/TaskDialogViewModelBase.cs +++ b/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 }; } /// @@ -43,6 +42,7 @@ public abstract class TaskDialogViewModelBase : ViewModelBase dialog = new TaskDialog { + Header = Title, Content = this, XamlRoot = App.VisualRoot, Buttons = { GetCloseButton() }