Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WPF] New IDialogService #1682

Merged
merged 6 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Sandbox/Wpf/HelloWorld/HelloWorld.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Prism Library", "Prism Libr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Wpf", "..\..\..\Source\Wpf\Prism.Wpf\Prism.Wpf.csproj", "{AA8ED3D6-A708-4187-8FAC-00F56E063AD7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Autofac.Wpf", "..\..\..\Source\Wpf\Prism.Autofac.Wpf\Prism.Autofac.Wpf.csproj", "{67921788-5D0F-4EC9-82C5-FDB5E2481E0C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Ninject.Wpf", "..\..\..\Source\Wpf\Prism.Ninject.Wpf\Prism.Ninject.Wpf.csproj", "{5263604A-39EC-4E7B-82DD-8F52C838A77A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.DryIoc.Wpf", "..\..\..\Source\Wpf\Prism.DryIoc.Wpf\Prism.DryIoc.Wpf.csproj", "{A0842858-BFD5-41AE-BDE7-CBD870BC9900}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Unity.Wpf", "..\..\..\Source\Wpf\Prism.Unity.Wpf\Prism.Unity.Wpf.csproj", "{DEBADAAB-5C78-444E-AA77-336A43B49EC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,23 +35,28 @@ Global
{AA8ED3D6-A708-4187-8FAC-00F56E063AD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA8ED3D6-A708-4187-8FAC-00F56E063AD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA8ED3D6-A708-4187-8FAC-00F56E063AD7}.Release|Any CPU.Build.0 = Release|Any CPU
{67921788-5D0F-4EC9-82C5-FDB5E2481E0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67921788-5D0F-4EC9-82C5-FDB5E2481E0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67921788-5D0F-4EC9-82C5-FDB5E2481E0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67921788-5D0F-4EC9-82C5-FDB5E2481E0C}.Release|Any CPU.Build.0 = Release|Any CPU
{5263604A-39EC-4E7B-82DD-8F52C838A77A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5263604A-39EC-4E7B-82DD-8F52C838A77A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5263604A-39EC-4E7B-82DD-8F52C838A77A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5263604A-39EC-4E7B-82DD-8F52C838A77A}.Release|Any CPU.Build.0 = Release|Any CPU
{A0842858-BFD5-41AE-BDE7-CBD870BC9900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0842858-BFD5-41AE-BDE7-CBD870BC9900}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0842858-BFD5-41AE-BDE7-CBD870BC9900}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0842858-BFD5-41AE-BDE7-CBD870BC9900}.Release|Any CPU.Build.0 = Release|Any CPU
{DEBADAAB-5C78-444E-AA77-336A43B49EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DEBADAAB-5C78-444E-AA77-336A43B49EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEBADAAB-5C78-444E-AA77-336A43B49EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DEBADAAB-5C78-444E-AA77-336A43B49EC3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{457AA668-72BB-4701-9A4E-FA86B0C412DE} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A}
{AA8ED3D6-A708-4187-8FAC-00F56E063AD7} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A}
{67921788-5D0F-4EC9-82C5-FDB5E2481E0C} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A}
{5263604A-39EC-4E7B-82DD-8F52C838A77A} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A}
{A0842858-BFD5-41AE-BDE7-CBD870BC9900} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A}
{DEBADAAB-5C78-444E-AA77-336A43B49EC3} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D877B086-37FD-4AA5-8AB3-CF7E87E27425}
Expand Down
16 changes: 7 additions & 9 deletions Sandbox/Wpf/HelloWorld/HelloWorld/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
using HelloWorld.Views;
using Prism.Ninject;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using HelloWorld.Dialogs;

namespace HelloWorld
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
public partial class App
{
protected override Window CreateShell()
{
Expand All @@ -23,7 +17,11 @@ protected override Window CreateShell()

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{

containerRegistry.RegisterDialog<NotificationDialog, NotificationDialogViewModel>();
containerRegistry.RegisterDialog<ConfirmationDialog, ConfirmationDialogViewModel>();

//register a custom window host
containerRegistry.RegisterDialogWindow<CustomDialogWindow>();
}
}
}
20 changes: 20 additions & 0 deletions Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/ConfirmationDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl x:Class="HelloWorld.Dialogs.ConfirmationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Width="300" Height="150">
<Grid x:Name="LayoutRoot" Margin="5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" Content="{Binding Message}"/>

<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="OK" Command="{Binding CloseDialogCommand}" CommandParameter="True" Width="75" Height="25" HorizontalAlignment="Right" Margin="0,10,0,0" />
<Button Content="Cancel" Command="{Binding CloseDialogCommand}" CommandParameter="False" Width="75" Height="25" HorizontalAlignment="Right" Margin="20,10,0,0" IsDefault="True"/>
</StackPanel>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 HelloWorld.Dialogs
{
/// <summary>
/// Interaction logic for ConfirmationDialog.xaml
/// </summary>
public partial class ConfirmationDialog : UserControl
{
public ConfirmationDialog()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace HelloWorld.Dialogs
{
public class ConfirmationDialogViewModel : NotificationDialogViewModel
{
public ConfirmationDialogViewModel()
{
Title = "Confirmation";
}
}
}
10 changes: 10 additions & 0 deletions Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/CustomDialogWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Window x:Class="HelloWorld.Dialogs.CustomDialogWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HelloWorld.Dialogs"
mc:Ignorable="d"
Title="Custom Dialog Window" Height="450" Width="800">

</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Prism.Services.Dialogs;
using System.Windows;

namespace HelloWorld.Dialogs
{
/// <summary>
/// Interaction logic for CustomDialogWindow.xaml
/// </summary>
public partial class CustomDialogWindow : Window, IDialogWindow
{
public CustomDialogWindow()
{
InitializeComponent();
}

public IDialogResult Result { get; set; }
}
}
16 changes: 16 additions & 0 deletions Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/NotificationDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<UserControl x:Class="HelloWorld.Dialogs.NotificationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Width="300" Height="150">
<Grid x:Name="LayoutRoot" Margin="5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock Text="{Binding Message}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" TextWrapping="Wrap" />
<Button Command="{Binding CloseDialogCommand}" Content="OK" Width="75" Height="25" HorizontalAlignment="Right" Margin="0,10,0,0" Grid.Row="1" IsDefault="True" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 HelloWorld.Dialogs
{
/// <summary>
/// Interaction logic for NotificationDialog.xaml
/// </summary>
public partial class NotificationDialog : UserControl
{
public NotificationDialog()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Prism.Services.Dialogs;

namespace HelloWorld.Dialogs
{
public class NotificationDialogViewModel : DialogViewModelBase
{
private string _message;
public string Message
{
get { return _message; }
set { SetProperty(ref _message, value); }
}

public NotificationDialogViewModel()
{
Title = "Notification";
}

public override void OnDialogOpened(IDialogParameters parameters)
{
Message = parameters.GetValue<string>("message");
}
}
}
29 changes: 26 additions & 3 deletions Sandbox/Wpf/HelloWorld/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="Dialogs\ConfirmationDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\CustomDialogWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\NotificationDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -68,6 +80,17 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Dialogs\ConfirmationDialog.xaml.cs">
<DependentUpon>ConfirmationDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\ConfirmationDialogViewModel.cs" />
<Compile Include="Dialogs\CustomDialogWindow.xaml.cs">
<DependentUpon>CustomDialogWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\NotificationDialog.xaml.cs">
<DependentUpon>NotificationDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\NotificationDialogViewModel.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
Expand Down Expand Up @@ -102,9 +125,9 @@
<Project>{457aa668-72bb-4701-9a4e-fa86b0c412de}</Project>
<Name>Prism</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Source\Wpf\Prism.Ninject.Wpf\Prism.Ninject.Wpf.csproj">
<Project>{5263604a-39ec-4e7b-82dd-8f52c838a77a}</Project>
<Name>Prism.Ninject.Wpf</Name>
<ProjectReference Include="..\..\..\..\Source\Wpf\Prism.DryIoc.Wpf\Prism.DryIoc.Wpf.csproj">
<Project>{a0842858-bfd5-41ae-bde7-cbd870bc9900}</Project>
<Name>Prism.DryIoc.Wpf</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Source\Wpf\Prism.Wpf\Prism.Wpf.csproj">
<Project>{aa8ed3d6-a708-4187-8fac-00f56e063ad7}</Project>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,83 @@
using Prism.Mvvm;
using System;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;

namespace HelloWorld.ViewModels
{
public class MainWindowViewModel : BindableBase
{
private string _title = "Prism Application";
private readonly IDialogService _dialogService;

public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}

public MainWindowViewModel()
public DelegateCommand ShowDialogCommand { get; private set; }

public MainWindowViewModel(IDialogService dialogService)
{
_dialogService = dialogService;
ShowDialogCommand = new DelegateCommand(ShowDialog);
}

private void ShowDialog()
{
var message = "This is a message that should be shown in the dialog.";

//using the dialog service as-is
//_dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), r =>
//{
// if (!r.Result.HasValue)
// Title = "Result is null";
// else if (r.Result == true)
// Title = "Result is True";
// else if (r.Result == false)
// Title = "Result is False";
// else
// Title = "What the hell did you do?";
//});

//using custom extenions methods to simplify the app's dialogs
//_dialogService.ShowNotification(message, r =>
//{
// if (!r.Result.HasValue)
// Title = "Result is null";
// else if (r.Result == true)
// Title = "Result is True";
// else if (r.Result == false)
// Title = "Result is False";
// else
// Title = "What the hell did you do?";
//});

_dialogService.ShowConfirmation(message, r =>
{
if (!r.Result.HasValue)
Title = "Result is null";
else if (r.Result == true)
Title = "Result is True";
else if (r.Result == false)
Title = "Result is False";
else
Title = "What the hell did you do?";
});
}
}

public static class DialogServiceEstensions
{
public static void ShowNotification(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
{
dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack);
}

public static void ShowConfirmation(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
{
dialogService.ShowDialog("ConfirmationDialog", new DialogParameters($"message={message}"), callBack);
}
}
}
4 changes: 3 additions & 1 deletion Sandbox/Wpf/HelloWorld/HelloWorld/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="350" Width="525">

<Grid>
<ContentControl prism:RegionManager.RegionName="ContentRegion" />
<Button Command="{Binding ShowDialogCommand}" Content="Show Dialog" />
<!--<ContentControl prism:RegionManager.RegionName="ContentRegion" />-->
</Grid>
</Window>
Loading