-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't propagate DataContext via Border.Child
Restore the Uno 2.x behaviour whereby Border.ChildProperty doesn't propagate inherited values (including DataContext) to the property value. The inheritance is handled by the visual tree in the normal case (since Child is always a view). This restores the ability for the framework to call SetParent() to simulate a different inheritance hierarchy than the actual visual tree configuration, eg for AppBarButton using the native style.
- Loading branch information
1 parent
c70114f
commit 0dc34bd
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ts/Tests/Windows_UI_Xaml_Controls/FramePages/Page_With_AppBarButton_Visibility_Bound.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,22 @@ | ||
<Page | ||
x:Class="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.FramePages.Page_With_AppBarButton_Visibility_Bound" | ||
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.FramePages" | ||
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> | ||
<CommandBar Content="Page with AppBarButton"> | ||
<CommandBar.PrimaryCommands> | ||
<AppBarButton Visibility="{Binding ButtonVisibility, FallbackValue=Collapsed}"> | ||
<TextBlock x:Name="innerTextBlock" | ||
x:FieldModifier="public" | ||
Text="{Binding ButtonText}" /> | ||
</AppBarButton> | ||
</CommandBar.PrimaryCommands> | ||
</CommandBar> | ||
</Grid> | ||
</Page> |
30 changes: 30 additions & 0 deletions
30
...Tests/Windows_UI_Xaml_Controls/FramePages/Page_With_AppBarButton_Visibility_Bound.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.FramePages | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class Page_With_AppBarButton_Visibility_Bound : Page | ||
{ | ||
public Page_With_AppBarButton_Visibility_Bound() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AppBarButton.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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Uno.UI.RuntimeTests.Helpers; | ||
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.FramePages; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using static Private.Infrastructure.TestServices; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls | ||
{ | ||
[TestClass] | ||
[RunsOnUIThread] | ||
public class Given_AppBarButton | ||
{ | ||
[TestMethod] | ||
public async Task Check_DataContext_Propagation() | ||
{ | ||
using (StyleHelper.UseNativeFrameNavigation()) | ||
{ | ||
var frame = new Frame(); | ||
WindowHelper.WindowContent = frame; | ||
await WindowHelper.WaitForIdle(); | ||
frame.Navigate(typeof(Page_With_AppBarButton_Visibility_Bound)); | ||
await WindowHelper.WaitForIdle(); | ||
var page = frame.Content as Page_With_AppBarButton_Visibility_Bound; | ||
Assert.IsNotNull(page); | ||
page.DataContext = new MyContext(); | ||
await WindowHelper.WaitForIdle(); | ||
var tb = page.innerTextBlock; | ||
Assert.IsNotNull(tb); | ||
Assert.AreEqual("Archaeopteryx", tb.Text); | ||
Assert.IsTrue(tb.ActualWidth > 0); | ||
Assert.IsTrue(tb.ActualHeight > 0); | ||
} | ||
} | ||
|
||
private class MyContext | ||
{ | ||
public Visibility ButtonVisibility => Visibility.Visible; | ||
public string ButtonText => "Archaeopteryx"; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Border.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,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Data; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls | ||
{ | ||
[TestClass] | ||
[RunsOnUIThread] | ||
public class Given_Border | ||
{ | ||
[TestMethod] | ||
public void Check_DataContext_Propagation() | ||
{ | ||
var tb = new TextBlock(); | ||
tb.SetBinding(TextBlock.TextProperty, new Binding { Path = new PropertyPath("TestText") }); | ||
var SUT = new Border | ||
{ | ||
Child = tb | ||
}; | ||
|
||
var root = new Grid | ||
{ | ||
DataContext = new MyContext() | ||
}; | ||
|
||
root.Children.Add(SUT); | ||
|
||
Assert.AreEqual("Vampire squid", tb.Text); | ||
} | ||
|
||
private class MyContext | ||
{ | ||
public string TestText => "Vampire squid"; | ||
} | ||
} | ||
} |
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