-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(popup): Put Popup in Parent hierarchy of its Child content.
Set Popup as Parent of PopupPanel. This emulates UWP behavior that the Popup is a Parent of one of the parents of the Child content, which is relied upon in some cases (eg WCT DataGrid relies upon this for focus management).
- Loading branch information
1 parent
afbfd2e
commit 765a2b6
Showing
4 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls_Primitives/Given_Popup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls_Primitives.PopupPages; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Media; | ||
using static Private.Infrastructure.TestServices; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls_Primitives | ||
{ | ||
[TestClass] | ||
[RunsOnUIThread] | ||
public class Given_Popup | ||
{ | ||
[TestMethod] | ||
public async Task Check_Can_Reach_Main_Visual_Tree() | ||
{ | ||
var page = new ReachMainTreePage(); | ||
WindowHelper.WindowContent = page; | ||
|
||
await WindowHelper.WaitForLoaded(page); | ||
|
||
Assert.IsTrue(CanReach(page.DummyTextBlock, page)); | ||
|
||
try | ||
{ | ||
page.TargetPopup.IsOpen = true; | ||
await WindowHelper.WaitForLoaded(page.PopupButton); | ||
|
||
Assert.IsTrue(CanReach(page.PopupButton, page)); | ||
} | ||
finally | ||
{ | ||
page.TargetPopup.IsOpen = false; | ||
} | ||
} | ||
|
||
#if __ANDROID__ | ||
[TestMethod] | ||
public async Task Check_Can_Reach_Main_Visual_Tree_Alternate_Mode() | ||
{ | ||
var originalConfig = FeatureConfiguration.Popup.UseNativePopup; | ||
FeatureConfiguration.Popup.UseNativePopup = !originalConfig; | ||
try | ||
{ | ||
await Check_Can_Reach_Main_Visual_Tree(); | ||
} | ||
finally | ||
{ | ||
FeatureConfiguration.Popup.UseNativePopup = originalConfig; | ||
} | ||
} | ||
#endif | ||
|
||
private static bool CanReach(DependencyObject startingElement, DependencyObject targetElement) | ||
{ | ||
var currentElement = startingElement; | ||
while (currentElement != null) | ||
{ | ||
if (currentElement == targetElement) | ||
{ | ||
return true; | ||
} | ||
|
||
// Quoting WCT DataGrid: | ||
// // Walk up the visual tree. Try using the framework element's | ||
// // parent. We do this because Popups behave differently with respect to the visual tree, | ||
// // and it could have a parent even if the VisualTreeHelper doesn't find it. | ||
DependencyObject parent = null; | ||
if (currentElement is FrameworkElement fe) | ||
{ | ||
parent = fe.Parent; | ||
} | ||
if (parent == null) | ||
{ | ||
parent = VisualTreeHelper.GetParent(currentElement); | ||
} | ||
|
||
currentElement = parent; | ||
} | ||
|
||
// Did not hit targetElement | ||
return false; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
....RuntimeTests/Tests/Windows_UI_Xaml_Controls_Primitives/PopupPages/ReachMainTreePage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Page x:Class="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls_Primitives.PopupPages.ReachMainTreePage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls_Primitives.PopupPages" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<TextBlock x:Name="DummyTextBlock" | ||
x:FieldModifier="public" | ||
Text="Page with Popup" /> | ||
<Popup x:Name="TargetPopup" | ||
x:FieldModifier="public"> | ||
<StackPanel> | ||
<TextBlock Text="Popup content" /> | ||
<Grid> | ||
<Button x:Name="PopupButton" | ||
x:FieldModifier="public" | ||
Content="Button in Popup" /> | ||
</Grid> | ||
</StackPanel> | ||
</Popup> | ||
</Grid> | ||
</Page> |
30 changes: 30 additions & 0 deletions
30
...ntimeTests/Tests/Windows_UI_Xaml_Controls_Primitives/PopupPages/ReachMainTreePage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
|
||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls_Primitives.PopupPages | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class ReachMainTreePage : Page | ||
{ | ||
public ReachMainTreePage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters