mirror of
https://github.com/holgerb83/ModernWpfPlayground.git
synced 2025-04-19 23:03:49 +02:00
Try to let it work
This commit is contained in:
parent
7ad587228a
commit
b1d1f2a396
@ -3,6 +3,7 @@ using Dialogs;
|
|||||||
using ModernWpf;
|
using ModernWpf;
|
||||||
using ModernWpfPlayground.Types;
|
using ModernWpfPlayground.Types;
|
||||||
using Prism.Ioc;
|
using Prism.Ioc;
|
||||||
|
using Prism.Services.Dialogs;
|
||||||
|
|
||||||
namespace ModernWpfPlayground
|
namespace ModernWpfPlayground
|
||||||
{
|
{
|
||||||
@ -21,6 +22,7 @@ namespace ModernWpfPlayground
|
|||||||
|
|
||||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||||
{
|
{
|
||||||
|
containerRegistry.RegisterSingleton<IDialogService, Dialogs.DialogService>();
|
||||||
containerRegistry.Register<MainWindow>();
|
containerRegistry.Register<MainWindow>();
|
||||||
containerRegistry.Register<MainWindowViewModel>();
|
containerRegistry.Register<MainWindowViewModel>();
|
||||||
containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>();
|
containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>();
|
||||||
|
@ -8,6 +8,7 @@ using Microsoft.Win32;
|
|||||||
using ModernWpfPlayground.MvvmStuff;
|
using ModernWpfPlayground.MvvmStuff;
|
||||||
using ModernWpfPlayground.Types;
|
using ModernWpfPlayground.Types;
|
||||||
using Prism.Commands;
|
using Prism.Commands;
|
||||||
|
using Prism.Logging;
|
||||||
using Prism.Services.Dialogs;
|
using Prism.Services.Dialogs;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
using static ModernWpf.ThemeManager;
|
using static ModernWpf.ThemeManager;
|
||||||
@ -18,15 +19,17 @@ namespace ModernWpfPlayground
|
|||||||
public class MainWindowViewModel : BaseViewModel
|
public class MainWindowViewModel : BaseViewModel
|
||||||
{
|
{
|
||||||
private readonly IDialogService _service;
|
private readonly IDialogService _service;
|
||||||
|
private readonly ILoggerFacade _logger;
|
||||||
private const string AppName = "TaBEA 3.0.0";
|
private const string AppName = "TaBEA 3.0.0";
|
||||||
private string? _path;
|
private string? _path;
|
||||||
private string _title = AppName;
|
private string _title = AppName;
|
||||||
private readonly ISerializer _serializer;
|
private readonly ISerializer _serializer;
|
||||||
private readonly IDeserializer _deserializer;
|
private readonly IDeserializer _deserializer;
|
||||||
|
|
||||||
public MainWindowViewModel(IDialogService service)
|
public MainWindowViewModel(IDialogService service, ILoggerFacade logger)
|
||||||
{
|
{
|
||||||
_service = service;
|
_service = service;
|
||||||
|
_logger = logger;
|
||||||
ShowDialogCommand = new DelegateCommand(ShowDialog);
|
ShowDialogCommand = new DelegateCommand(ShowDialog);
|
||||||
CloseCommand = new DelegateCommand(() => Application.Current.Shutdown());
|
CloseCommand = new DelegateCommand(() => Application.Current.Shutdown());
|
||||||
OpenViewModelCommand = new DelegateCommand(LoadViewModel);
|
OpenViewModelCommand = new DelegateCommand(LoadViewModel);
|
||||||
@ -135,12 +138,12 @@ namespace ModernWpfPlayground
|
|||||||
|
|
||||||
private void ShowDialogService()
|
private void ShowDialogService()
|
||||||
{
|
{
|
||||||
void executeCallBack(IDialogResult result)
|
static void ExecuteCallBack(IDialogResult result)
|
||||||
{
|
{
|
||||||
|
MessageBox.Show(Application.Current.MainWindow, "DialogResult = " + result.Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
_service.Show(nameof(MessageBoxView), default, executeCallBack);
|
_service.ShowDialog(nameof(MessageBoxView), default, ExecuteCallBack);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,32 +1,103 @@
|
|||||||
//using System;
|
using System;
|
||||||
//using Prism.Services.Dialogs;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using ModernWpf.Controls;
|
||||||
|
using Prism.Common;
|
||||||
|
using Prism.Ioc;
|
||||||
|
using Prism.Services.Dialogs;
|
||||||
|
|
||||||
//namespace Dialogs
|
namespace Dialogs
|
||||||
//{
|
{
|
||||||
// public class DialogService : IDialogService
|
/// <summary>
|
||||||
// {
|
/// Implements <see cref="IDialogService"/> to show modal and non-modal dialogs.
|
||||||
// /// <inheritdoc />
|
/// </summary>
|
||||||
// public void Show(string name, IDialogParameters parameters, Action<IDialogResult> callback)
|
/// <remarks>
|
||||||
// {
|
/// The dialog's ViewModel must implement IDialogAware.
|
||||||
// TODO_IMPLEMENT_ME();
|
/// </remarks>
|
||||||
// }
|
public class DialogService : IDialogService
|
||||||
|
{
|
||||||
|
private readonly IContainerExtension _containerExtension;
|
||||||
|
|
||||||
// /// <inheritdoc />
|
/// <summary>
|
||||||
// public void Show(string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
|
/// Initializes a new instance of the <see cref="DialogService"/> class.
|
||||||
// {
|
/// </summary>
|
||||||
// TODO_IMPLEMENT_ME();
|
/// <param name="containerExtension"></param>
|
||||||
// }
|
public DialogService(IContainerExtension containerExtension)
|
||||||
|
{
|
||||||
|
_containerExtension = containerExtension;
|
||||||
|
}
|
||||||
|
|
||||||
// /// <inheritdoc />
|
/// <summary>
|
||||||
// public void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback)
|
/// Shows a non-modal dialog.
|
||||||
// {
|
/// </summary>
|
||||||
// TODO_IMPLEMENT_ME();
|
/// <param name="name">The name of the dialog to show.</param>
|
||||||
// }
|
/// <param name="parameters">The parameters to pass to the dialog.</param>
|
||||||
|
/// <param name="callback">The action to perform when the dialog is closed.</param>
|
||||||
|
public void Show(string name, IDialogParameters parameters, Action<IDialogResult> callback)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
// /// <inheritdoc />
|
/// <summary>
|
||||||
// public void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
|
/// Shows a non-modal dialog.
|
||||||
// {
|
/// </summary>
|
||||||
// TODO_IMPLEMENT_ME();
|
/// <param name="name">The name of the dialog to show.</param>
|
||||||
// }
|
/// <param name="parameters">The parameters to pass to the dialog.</param>
|
||||||
// }
|
/// <param name="callback">The action to perform when the dialog is closed.</param>
|
||||||
//}
|
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
|
||||||
|
public void Show(string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows a modal dialog.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the dialog to show.</param>
|
||||||
|
/// <param name="parameters">The parameters to pass to the dialog.</param>
|
||||||
|
/// <param name="callback">The action to perform when the dialog is closed.</param>
|
||||||
|
public void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback)
|
||||||
|
{
|
||||||
|
ShowDialogInternal(name, parameters, callback, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows a modal dialog.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the dialog to show.</param>
|
||||||
|
/// <param name="parameters">The parameters to pass to the dialog.</param>
|
||||||
|
/// <param name="callback">The action to perform when the dialog is closed.</param>
|
||||||
|
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
|
||||||
|
public void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback,
|
||||||
|
string windowName)
|
||||||
|
{
|
||||||
|
ShowDialogInternal(name, parameters, callback, windowName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowDialogInternal(string name, IDialogParameters parameters, Action<IDialogResult> callback,
|
||||||
|
string windowName)
|
||||||
|
{
|
||||||
|
var content = _containerExtension.Resolve<object>(name);
|
||||||
|
if (!(content is ContentDialog contentDialog))
|
||||||
|
throw new NullReferenceException("A dialog's content must be a content dialog");
|
||||||
|
|
||||||
|
if (!(contentDialog.DataContext is IDialogAware viewModel))
|
||||||
|
throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAware interface");
|
||||||
|
|
||||||
|
MvvmHelpers.ViewAndViewModelAction<IDialogAware>(viewModel, d => d.OnDialogOpened(parameters));
|
||||||
|
Action<IDialogResult> closeHandler = default;
|
||||||
|
|
||||||
|
closeHandler += e =>
|
||||||
|
{
|
||||||
|
viewModel.RequestClose -= closeHandler;
|
||||||
|
callback?.Invoke(e);
|
||||||
|
};
|
||||||
|
viewModel.RequestClose += closeHandler;
|
||||||
|
|
||||||
|
if (contentDialog.Owner == null)
|
||||||
|
contentDialog.Owner = Application.Current?.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);
|
||||||
|
contentDialog.ShowAsync().Await();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:mvvm="http://prismlibrary.com/"
|
xmlns:mvvm="http://prismlibrary.com/"
|
||||||
xmlns:ui="http://schemas.modernwpf.com/2019"
|
xmlns:ui="http://schemas.modernwpf.com/2019"
|
||||||
Title="Save your work?"
|
Title="{Binding Title}"
|
||||||
d:DataContext="{d:DesignInstance local:MessageBoxViewModel}"
|
d:DataContext="{d:DesignInstance local:MessageBoxViewModel}"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Dialogs
|
namespace Dialogs
|
||||||
{
|
{
|
||||||
@ -21,6 +11,7 @@ namespace Dialogs
|
|||||||
public MessageBoxView()
|
public MessageBoxView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Owner = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace Dialogs
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Title { get; }
|
public string Title { get; } = "Hallo Holger";
|
||||||
|
|
||||||
|
|
||||||
private DelegateCommand<string> _closeDialogCommand;
|
private DelegateCommand<string> _closeDialogCommand;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user