mirror of
https://github.com/PrismLibrary/Prism.git
synced 2026-10-29 13:38:03 +08:00
chore: adding DialogSample for Uno App
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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!" }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user