chore: adding DialogSample for Uno App

This commit is contained in:
Dan Siegel
2023-10-07 12:18:49 -06:00
parent a45c90dd9e
commit c54ceca28c
5 changed files with 25 additions and 51 deletions
+2 -4
View File
@@ -10,11 +10,9 @@
d:DesignWidth="400">
<StackPanel>
<TextBlock Text="{Binding Title}"
FontSize="20"
FontWeight="Bold" />
<TextBlock Text="{Binding Message}" />
<Button Content="OK"
Command="{Binding CloseCommand}" />
Command="{Binding CloseCommand}"
Margin="0,15"/>
</StackPanel>
</UserControl>
+3
View File
@@ -1,4 +1,6 @@
using ModuleA.Dialogs;
using ModuleA.Views;
using AlertDialog = ModuleA.Dialogs.AlertDialog;
namespace ModuleA;
@@ -15,6 +17,7 @@ public class ModuleAModule : IModule
{
containerRegistry.RegisterForNavigation<ViewA>();
containerRegistry.RegisterForNavigation<ViewB>();
containerRegistry.RegisterDialog<AlertDialog, AlertDialogViewModel>();
}
public void OnInitialized(IContainerProvider containerProvider)
+17 -7
View File
@@ -1,16 +1,26 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace ModuleA.ViewModels;
internal class ViewAViewModel : ViewModelBase
{
public ViewAViewModel(IRegionManager regionManager)
private readonly IDialogService _dialogService;
public ViewAViewModel(IRegionManager regionManager, IDialogService dialogService)
: base(regionManager)
{
_dialogService = dialogService;
ShowAlertCommand = new DelegateCommand(ShowDialog);
}
public ICommand ShowAlertCommand { get; }
private void ShowDialog()
{
_dialogService.ShowDialog("AlertDialog", new DialogParameters
{
{ "title", "Oh Snap" },
{ "message", "You can actually create much more amazing dialogs with Prism. Hello from ViewA!" }
});
}
}
+3 -2
View File
@@ -9,7 +9,8 @@
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<StackPanel>
<TextBlock Text="View A" FontSize="72" />
</Grid>
<Button Content="Show Dialog" Command="{Binding ShowAlertCommand}" />
</StackPanel>
</UserControl>
@@ -72,43 +72,5 @@ namespace Prism.Dialogs
return parameters;
}
#endif
/// <summary>
/// Shows a modal dialog.
/// </summary>
/// <param name="dialogService">The DialogService</param>
/// <param name="name">The name of the dialog to show.</param>
public static void ShowDialog(this IDialogService dialogService, string name)
{
dialogService.ShowDialog(name, new DialogParameters(), DialogCallback.Empty);
}
/// <summary>
/// Shows a modal dialog.
/// </summary>
/// <param name="dialogService">The DialogService</param>
/// <param name="name">The name of the dialog to show.</param>
/// <param name="callback">The action to perform when the dialog is closed.</param>
public static void ShowDialog(this IDialogService dialogService, string name, Action<IDialogResult> callback)
{
dialogService.ShowDialog(name, new DialogParameters(), new DialogCallback().OnClose(callback));
}
/// <summary>
/// Shows a modal dialog.
/// </summary>
/// <param name="dialogService">The DialogService</param>
/// <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 static void ShowDialog(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
{
parameters ??= new DialogParameters();
if (!string.IsNullOrEmpty(windowName))
parameters.Add(KnownDialogParameters.WindowName, windowName);
dialogService.ShowDialog(name, parameters, new DialogCallback().OnClose(callback));
}
}
}