Skip to content

Commit

Permalink
Merge pull request #3001 from PrismLibrary/dev/ds/refactor-xamlroot-d…
Browse files Browse the repository at this point in the history
…ialogs
  • Loading branch information
dansiegel authored Nov 14, 2023
2 parents b5c5f72 + 7492350 commit 0563e4d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
8 changes: 3 additions & 5 deletions e2e/Uno/HelloWorld/Views/Shell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
x:Class="HelloWorld.Views.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:pr="using:Prism.Navigation.Regions"
xmlns:pvm="using:Prism.Mvvm"
xmlns:prism="using:Prism.Navigation.Regions"
xmlns:toolkit="using:Uno.Toolkit.UI"
pvm:ViewModelLocator.AutowireViewModel="true"
xmlns:local="using:HelloWorld.Views"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >

Expand Down Expand Up @@ -48,8 +46,8 @@
<Button Command="{Binding NavigateCommand}" CommandParameter="ViewB">Navigate to View B</Button>
</StackPanel>
</StackPanel>
<ContentControl Grid.Row="1" pr:RegionManager.RegionName="ContentRegion" />-->
<NavigationView pr:RegionManager.RegionName="ContentRegion"
<ContentControl Grid.Row="1" prism:RegionManager.RegionName="ContentRegion" />-->
<NavigationView prism:RegionManager.RegionName="ContentRegion"
IsSettingsVisible="false">
<NavigationView.MenuItems>
<NavigationViewItem Content="View A" Tag="ViewA" />
Expand Down
12 changes: 8 additions & 4 deletions src/Uno/Prism.Uno/Dialogs/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ public async void ShowDialog(string name, IDialogParameters parameters, DialogCa
parameters ??= new DialogParameters();
var windowName = parameters.TryGetValue<string>(KnownDialogParameters.WindowName, out var wName) ? wName : null;

IDialogWindow contentDialog = CreateDialogWindow(windowName);
ConfigureDialogWindowEvents(contentDialog, callback);
ConfigureDialogWindowContent(name, contentDialog, parameters);
var dialogWindow = CreateDialogWindow(windowName);
if (dialogWindow is ContentDialog contentDialog)
{
contentDialog.XamlRoot = _containerProvider.Resolve<Window>().Content.XamlRoot;
}
ConfigureDialogWindowEvents(dialogWindow, callback);
ConfigureDialogWindowContent(name, dialogWindow, parameters);

var placement = parameters.ContainsKey(KnownDialogParameters.DialogPlacement) ?
(parameters[KnownDialogParameters.DialogPlacement] is ContentDialogPlacement placementValue ? placementValue : Enum.Parse<ContentDialogPlacement>(parameters[KnownDialogParameters.DialogPlacement].ToString() ?? string.Empty)) : ContentDialogPlacement.Popup;

await contentDialog.ShowAsync(placement);
await dialogWindow.ShowAsync(placement);
}
catch (Exception ex)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Uno/Prism.Uno/Dialogs/DialogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ namespace Prism.Dialogs
/// </summary>
public partial class DialogWindow : ContentDialog, IDialogWindow
{
public DialogWindow(Window window)
public DialogWindow()
{
this.InitializeComponent();
XamlRoot = window.Content.XamlRoot;
}
public IDialogResult? Result { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public async Task ExecuteAsync_WithCancellationToken_ShouldExecuteCommandAsynchr
// Arrange
bool executionStarted = false;
bool executed = false;
var command = new AsyncDelegateCommand(Execute);
bool taskCancelled = false;
var command = new AsyncDelegateCommand(Execute)
.Catch<TaskCanceledException>(ex =>
{
taskCancelled = true;
});

async Task Execute(CancellationToken token)
{
Expand All @@ -116,6 +121,7 @@ async Task Execute(CancellationToken token)
// Assert
Assert.True(executionStarted);
Assert.False(executed);
Assert.True(taskCancelled);
}

[Fact]
Expand Down

0 comments on commit 0563e4d

Please sign in to comment.