-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1682 from PrismLibrary/Interactivity-Improvements
[WPF] New IDialogService
- Loading branch information
Showing
40 changed files
with
686 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/ConfirmationDialog.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/ConfirmationDialog.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/ConfirmationDialogViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/CustomDialogWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
18 changes: 18 additions & 0 deletions
18
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/CustomDialogWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/NotificationDialog.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/NotificationDialog.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/NotificationDialogViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 66 additions & 2 deletions
68
Sandbox/Wpf/HelloWorld/HelloWorld/ViewModels/MainWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.