Skip to content

Commit

Permalink
chore: adding DialogSample for Uno App
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Oct 7, 2023
1 parent a45c90d commit c54ceca
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 51 deletions.
6 changes: 2 additions & 4 deletions e2e/Uno/ModuleA/Dialogs/AlertDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions e2e/Uno/ModuleA/ModuleAModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ModuleA.Dialogs;
using ModuleA.Views;
using AlertDialog = ModuleA.Dialogs.AlertDialog;

namespace ModuleA;

Expand All @@ -15,6 +17,7 @@ public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<ViewA>();
containerRegistry.RegisterForNavigation<ViewB>();
containerRegistry.RegisterDialog<AlertDialog, AlertDialogViewModel>();
}

public void OnInitialized(IContainerProvider containerProvider)
Expand Down
24 changes: 17 additions & 7 deletions e2e/Uno/ModuleA/ViewModels/ViewAViewModel.cs
Original file line number Diff line number Diff line change
@@ -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!" }
});
}
}
5 changes: 3 additions & 2 deletions e2e/Uno/ModuleA/Views/ViewA.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
38 changes: 0 additions & 38 deletions src/Wpf/Prism.Wpf/Dialogs/IDialogServiceCompatExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,5 @@ private static IDialogParameters EnsureShowNonModalParameter(IDialogParameters p
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));
}
}
}

0 comments on commit c54ceca

Please sign in to comment.