Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Window dependency in DialogWindow #3001

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading