-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix spurious DataContext propagation in ContentControl
- Loading branch information
1 parent
101e5bf
commit 996d574
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...RuntimeTests/Tests/Windows_UI_Xaml_Controls/ContentControlPages/BoundContentApplicator.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,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.ContentControlPages | ||
{ | ||
public partial class BoundContentApplicator : Grid | ||
{ | ||
public object PseudoContent | ||
{ | ||
get { return (object)GetValue(PseudoContentProperty); } | ||
set { SetValue(PseudoContentProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty PseudoContentProperty = | ||
DependencyProperty.Register("PseudoContent", typeof(object), typeof(BoundContentApplicator), new PropertyMetadata(null)); | ||
|
||
public void SpawnButton() | ||
{ | ||
var button = new Button(); // Since we create the Button from code, its default style and its template will only be applied when it's loaded into the visual tree | ||
button.Content = PseudoContent; | ||
Children.Add(button); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ls/ContentControlPages/When_Template_Applied_On_Loading_DataContext_Propagation_Page.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.ContentControlPages.When_Template_Applied_On_Loading_DataContext_Propagation_Page" | ||
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.ContentControlPages" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<StackPanel Margin="0,50,0,0" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<Button x:Name="AddButtonButton" | ||
Content="Add test button" | ||
Click="AddBoundContentButton" /> | ||
<local:BoundContentApplicator x:Name="SpawnedButtonHost" x:FieldModifier="public"> | ||
<local:BoundContentApplicator.PseudoContent> | ||
<ComboBox ItemsSource="{Binding MyItemsSource}" | ||
SelectedItem="{Binding MyText, Mode=TwoWay}" /> | ||
</local:BoundContentApplicator.PseudoContent> | ||
</local:BoundContentApplicator> | ||
</StackPanel> | ||
</Page> |
57 changes: 57 additions & 0 deletions
57
...ContentControlPages/When_Template_Applied_On_Loading_DataContext_Propagation_Page.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,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
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.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.ContentControlPages | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class When_Template_Applied_On_Loading_DataContext_Propagation_Page : Page | ||
{ | ||
public When_Template_Applied_On_Loading_DataContext_Propagation_Page() | ||
{ | ||
this.InitializeComponent(); | ||
DataContext = new ViewModel() { MyItemsSource = new[] { "Froot", "Veg" }, MyText = "Froot" }; | ||
} | ||
|
||
private void AddBoundContentButton(object sender, object args) | ||
{ | ||
SpawnedButtonHost.SpawnButton(); | ||
} | ||
|
||
private class ViewModel : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public IEnumerable<string> MyItemsSource { get; set; } | ||
|
||
public string MyText | ||
{ | ||
get { return _myText; } | ||
set | ||
{ | ||
if (_myText != value) | ||
{ | ||
_myText = value; | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MyText))); | ||
} | ||
} | ||
} | ||
string _myText; | ||
} | ||
} | ||
} |
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
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