mirror of
				https://github.com/holgerb83/ModernWpfPlayground.git
				synced 2025-10-31 00:11:19 +01:00 
			
		
		
		
	Try to create a prism dialog service with custom modern ui window
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| using System.Windows; | ||||
| using Dialogs; | ||||
| using ModernWpf; | ||||
| using ModernWpfPlayground.Types; | ||||
| using Prism.Ioc; | ||||
| @@ -22,6 +23,7 @@ namespace ModernWpfPlayground | ||||
|         { | ||||
|             containerRegistry.Register<MainWindow>(); | ||||
|             containerRegistry.Register<MainWindowViewModel>(); | ||||
|             containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>(); | ||||
|         } | ||||
|  | ||||
|         protected override Window CreateShell() | ||||
|   | ||||
| @@ -242,6 +242,7 @@ | ||||
|                                         HorizontalAlignment="Stretch" | ||||
|                                         Command="{Binding SaveViewModelCommand}" | ||||
|                                         Content="Save" /> | ||||
|                                     <Button Command="{Binding ShowDialogServiceCommand}" Content="Show dialog" /> | ||||
|                                 </ui:SimpleStackPanel> | ||||
|                             </Grid> | ||||
|                         </ScrollViewer> | ||||
| @@ -275,7 +276,8 @@ | ||||
|                                         x:Name="TextBoxSwitch" | ||||
|                                         Grid.Column="0" | ||||
|                                         Width="145" | ||||
|                                         Margin="0,0,5,0"> | ||||
|                                         Margin="0,0,5,0" | ||||
|                                         VerticalAlignment="Top"> | ||||
|                                         <ToggleButton.Style> | ||||
|                                             <Style BasedOn="{StaticResource {x:Type ToggleButton}}" TargetType="ToggleButton"> | ||||
|                                                 <Setter Property="Content" Value="Read/Write" /> | ||||
| @@ -289,8 +291,12 @@ | ||||
|                                     </ToggleButton> | ||||
|                                     <TextBox | ||||
|                                         Grid.Column="1" | ||||
|                                         AcceptsReturn="True" | ||||
|                                         AcceptsTab="True" | ||||
|                                         IsReadOnly="{Binding IsChecked, ElementName=TextBoxSwitch}" | ||||
|                                         Text="Eine einfache Textbox" /> | ||||
|                                         MinLines="4" | ||||
|                                         Text="{Binding MultiLineText}" | ||||
|                                         TextWrapping="Wrap" /> | ||||
|                                 </Grid> | ||||
|                                 <controls:PropertyPresenter Label="Hello" Value="{Binding BooleanValue}" /> | ||||
|                                 <controls:PropertyPresenter Label="Hello"> | ||||
|   | ||||
| @@ -3,10 +3,12 @@ using System.IO; | ||||
| using System.Threading.Tasks; | ||||
| using System.Windows; | ||||
| using System.Windows.Input; | ||||
| using Dialogs; | ||||
| using Microsoft.Win32; | ||||
| using ModernWpfPlayground.MvvmStuff; | ||||
| using ModernWpfPlayground.Types; | ||||
| using Prism.Commands; | ||||
| using Prism.Services.Dialogs; | ||||
| using YamlDotNet.Serialization; | ||||
| using static ModernWpf.ThemeManager; | ||||
|  | ||||
| @@ -15,14 +17,16 @@ namespace ModernWpfPlayground | ||||
|     // ReSharper disable once ClassNeverInstantiated.Global | ||||
|     public class MainWindowViewModel : BaseViewModel | ||||
|     { | ||||
|         private readonly IDialogService _service; | ||||
|         private const string AppName = "TaBEA 3.0.0"; | ||||
|         private string? _path; | ||||
|         private string _title = AppName; | ||||
|         private readonly ISerializer _serializer; | ||||
|         private readonly IDeserializer _deserializer; | ||||
|  | ||||
|         public MainWindowViewModel() | ||||
|         public MainWindowViewModel(IDialogService service) | ||||
|         { | ||||
|             _service = service; | ||||
|             ShowDialogCommand = new DelegateCommand(ShowDialog); | ||||
|             CloseCommand = new DelegateCommand(() => Application.Current.Shutdown()); | ||||
|             OpenViewModelCommand = new DelegateCommand(LoadViewModel); | ||||
| @@ -121,6 +125,25 @@ namespace ModernWpfPlayground | ||||
|             set => SetProperty(value); | ||||
|         } | ||||
|  | ||||
|         public string MultiLineText | ||||
|         { | ||||
|             get => GetProperty("Multi line"); | ||||
|             set => SetProperty(value); | ||||
|         } | ||||
|  | ||||
|         public ICommand ShowDialogServiceCommand => new DelegateCommand(ShowDialogService); | ||||
|  | ||||
|         private void ShowDialogService() | ||||
|         { | ||||
|             void executeCallBack(IDialogResult result) | ||||
|             { | ||||
|  | ||||
|             } | ||||
|  | ||||
|             _service.Show(nameof(MessageBoxView), default, executeCallBack); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         private static void SetTheme(ThemeMode themeMode) => Current.ApplicationTheme = themeMode.ToApplicationTheme(); | ||||
|  | ||||
|         private void ShowDialog() | ||||
|   | ||||
| @@ -9,7 +9,7 @@ | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="FastMember" Version="1.5.0" /> | ||||
|     <PackageReference Include="ModernWpfUI" Version="0.9.0" /> | ||||
|     <PackageReference Include="ModernWpfUI" Version="0.9.1" /> | ||||
|     <PackageReference Include="Prism.DryIoc" Version="8.0.0.1740-pre" /> | ||||
|     <PackageReference Include="Prism.Wpf" Version="8.0.0.1740-pre" /> | ||||
|     <PackageReference Include="YamlDotNet" Version="8.1.2" /> | ||||
| @@ -19,6 +19,7 @@ | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Controls\Controls.csproj" /> | ||||
|     <ProjectReference Include="..\Dialogs\Dialogs.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
| @@ -18,9 +18,9 @@ namespace ModernWpfPlayground.Types | ||||
|         { | ||||
|             return accentColor switch | ||||
|             { | ||||
|                 AccentColors.Green => Color.FromRgb(0, 86, 76), | ||||
|                 AccentColors.Green => Color.FromRgb(33, 115, 70), | ||||
|                 AccentColors.Yellow => Color.FromRgb(164, 144, 0), | ||||
|                 AccentColors.Blue => Color.FromRgb(0, 120, 215), | ||||
|                 AccentColors.Blue => Color.FromRgb(43, 87, 154), | ||||
|                 AccentColors.Purple => Color.FromRgb(104, 33, 122), | ||||
|                 AccentColors.Red => Color.FromRgb(183, 71, 42), | ||||
|                 _ => throw new ArgumentOutOfRangeException(nameof(accentColor), accentColor, null) | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="ModernWpfUI" Version="0.9.0" /> | ||||
|     <PackageReference Include="ModernWpfUI" Version="0.9.1" /> | ||||
|     <PackageReference Include="System.Drawing.Common" Version="4.7.0" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   | ||||
							
								
								
									
										10
									
								
								Dialogs/AssemblyInfo.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Dialogs/AssemblyInfo.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| using System.Windows; | ||||
|  | ||||
| [assembly: ThemeInfo( | ||||
|     ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||||
|                                      //(used if a resource is not found in the page, | ||||
|                                      // or application resource dictionaries) | ||||
|     ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||||
|                                               //(used if a resource is not found in the page, | ||||
|                                               // app, or any theme specific resource dictionaries) | ||||
| )] | ||||
							
								
								
									
										32
									
								
								Dialogs/DialogService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Dialogs/DialogService.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| //using System; | ||||
| //using Prism.Services.Dialogs; | ||||
|  | ||||
| //namespace Dialogs | ||||
| //{ | ||||
| //    public class DialogService : IDialogService | ||||
| //    { | ||||
| //        /// <inheritdoc /> | ||||
| //        public void Show(string name, IDialogParameters parameters, Action<IDialogResult> callback) | ||||
| //        { | ||||
| //            TODO_IMPLEMENT_ME(); | ||||
| //        } | ||||
|  | ||||
| //        /// <inheritdoc /> | ||||
| //        public void Show(string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName) | ||||
| //        { | ||||
| //            TODO_IMPLEMENT_ME(); | ||||
| //        } | ||||
|  | ||||
| //        /// <inheritdoc /> | ||||
| //        public void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback) | ||||
| //        { | ||||
| //            TODO_IMPLEMENT_ME(); | ||||
| //        } | ||||
|  | ||||
| //        /// <inheritdoc /> | ||||
| //        public void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName) | ||||
| //        { | ||||
| //            TODO_IMPLEMENT_ME(); | ||||
| //        } | ||||
| //    } | ||||
| //} | ||||
							
								
								
									
										18
									
								
								Dialogs/Dialogs.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Dialogs/Dialogs.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>netcoreapp3.1</TargetFramework> | ||||
|     <UseWPF>true</UseWPF> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Prism.Wpf" Version="8.0.0.1740-pre" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <Reference Include="ModernWpf.Controls"> | ||||
|       <HintPath>..\..\..\.nuget\packages\modernwpfui\0.9.1\lib\netcoreapp3.0\ModernWpf.Controls.dll</HintPath> | ||||
|     </Reference> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
							
								
								
									
										27
									
								
								Dialogs/MessageBoxView.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Dialogs/MessageBoxView.xaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| <ui:ContentDialog | ||||
|     x:Class="Dialogs.MessageBoxView" | ||||
|     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||||
|     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||||
|     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||||
|     xmlns:local="clr-namespace:Dialogs" | ||||
|     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||||
|     xmlns:mvvm="http://prismlibrary.com/" | ||||
|     xmlns:ui="http://schemas.modernwpf.com/2019" | ||||
|     Title="Save your work?" | ||||
|     d:DataContext="{d:DesignInstance local:MessageBoxViewModel}" | ||||
|     d:DesignHeight="450" | ||||
|     d:DesignWidth="800" | ||||
|     mvvm:ViewModelLocator.AutoWireViewModel="True" | ||||
|     CloseButtonText="Cancel" | ||||
|     DefaultButton="Primary" | ||||
|     PrimaryButtonCommand="{Binding CloseDialogCommand}" | ||||
|     PrimaryButtonCommandParameter="true" | ||||
|     PrimaryButtonText="Save" | ||||
|     SecondaryButtonText="Don't Save" | ||||
|     mc:Ignorable="d"> | ||||
|     <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> | ||||
|         <!--  Content body  --> | ||||
|         <TextBlock Text="Lorem ipsum dolor sit amet, adipisicing elit." TextWrapping="Wrap" /> | ||||
|         <CheckBox Content="Upload your content to the cloud." /> | ||||
|     </StackPanel> | ||||
| </ui:ContentDialog> | ||||
							
								
								
									
										26
									
								
								Dialogs/MessageBoxView.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Dialogs/MessageBoxView.xaml.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Text; | ||||
| 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 | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interaktionslogik für MessageBoxView.xaml | ||||
|     /// </summary> | ||||
|     public partial class MessageBoxView | ||||
|     { | ||||
|         public MessageBoxView() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
|          } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										50
									
								
								Dialogs/MessageBoxViewModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								Dialogs/MessageBoxViewModel.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| using System; | ||||
| using Prism.Commands; | ||||
| using Prism.Services.Dialogs; | ||||
|  | ||||
| namespace Dialogs | ||||
| { | ||||
|     public class MessageBoxViewModel : IDialogAware | ||||
|     { | ||||
|         /// <inheritdoc /> | ||||
|         public bool CanCloseDialog() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|  | ||||
|         /// <inheritdoc /> | ||||
|         public void OnDialogClosed() | ||||
|         { | ||||
|              | ||||
|         } | ||||
|  | ||||
|         /// <inheritdoc /> | ||||
|         public void OnDialogOpened(IDialogParameters parameters) | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         /// <inheritdoc /> | ||||
|         public string Title { get; } | ||||
|  | ||||
|  | ||||
|         private DelegateCommand<string> _closeDialogCommand; | ||||
|         public DelegateCommand<string> CloseDialogCommand => _closeDialogCommand ??= new DelegateCommand<string>(CloseDialog); | ||||
|  | ||||
|         private void CloseDialog(string obj) | ||||
|         { | ||||
|             if (obj == "true") | ||||
|             { | ||||
|                 RaiseRequestClose(new DialogResult(ButtonResult.OK)); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         /// <inheritdoc /> | ||||
|         public event Action<IDialogResult> RequestClose; | ||||
|  | ||||
|         public virtual void RaiseRequestClose(IDialogResult dialogResult) | ||||
|         { | ||||
|             RequestClose?.Invoke(dialogResult); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernWpfPlayground", "App\ | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls", "Controls\Controls.csproj", "{3884FD41-5A46-4A67-A147-57C36F0059DC}" | ||||
| EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dialogs", "Dialogs\Dialogs.csproj", "{56468B07-B709-43E9-8FB9-54EDD5219D69}" | ||||
| EndProject | ||||
| Global | ||||
| 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| 		Debug|Any CPU = Debug|Any CPU | ||||
| @@ -21,6 +23,10 @@ Global | ||||
| 		{3884FD41-5A46-4A67-A147-57C36F0059DC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{3884FD41-5A46-4A67-A147-57C36F0059DC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{3884FD41-5A46-4A67-A147-57C36F0059DC}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{56468B07-B709-43E9-8FB9-54EDD5219D69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{56468B07-B709-43E9-8FB9-54EDD5219D69}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{56468B07-B709-43E9-8FB9-54EDD5219D69}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{56468B07-B709-43E9-8FB9-54EDD5219D69}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 	EndGlobalSection | ||||
| 	GlobalSection(SolutionProperties) = preSolution | ||||
| 		HideSolutionNode = FALSE | ||||
|   | ||||
		Reference in New Issue
	
	Block a user