-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ItemsControl): ContentControl at the DataTemplate root should kee…
…p bindings
- Loading branch information
1 parent
e86db9c
commit 6542c27
Showing
5 changed files
with
212 additions
and
3 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TreeView.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,73 @@ | ||
using System; | ||
using System.Linq; | ||
using Windows.UI; | ||
using System.Threading.Tasks; | ||
using Private.Infrastructure; | ||
using Uno.UI.RuntimeTests.Helpers; | ||
using Windows.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using TreeView = Microsoft.UI.Xaml.Controls.TreeView; | ||
using TreeViewItem = Microsoft.UI.Xaml.Controls.TreeViewItem; | ||
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.TreeViewTests; | ||
using System.Collections.Generic; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls; | ||
|
||
[TestClass] | ||
[RunsOnUIThread] | ||
public class Given_TreeView | ||
{ | ||
// Test method that create a tree of three nested items from a itemssource and that will open and close a single treeview item twice and validate that the container is still containing the same property values | ||
[TestMethod] | ||
public async Task When_Open_Close_Twice() | ||
{ | ||
var SUT = new When_Open_Close_Twice(); | ||
TestServices.WindowHelper.WindowContent = SUT; | ||
|
||
var root = new MyNode(); | ||
root.Name = "root"; | ||
root.Children = new List<MyNode>(); | ||
var child1 = new MyNode { Name = "Child 1" }; | ||
var child2 = new MyNode { Name = "Child 2" }; | ||
root.Children.Add(child1); | ||
root.Children.Add(child2); | ||
|
||
SUT.myTree.ItemsSource = new[] { root }; | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
var rootNode = (TreeViewItem)SUT.FindName("root"); | ||
rootNode.IsExpanded = true; | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
var child1Node = (TreeViewItem)SUT.FindName("Child 1"); | ||
Assert.IsNotNull(child1Node); | ||
Assert.AreEqual("Child 1", child1Node.Content); | ||
|
||
rootNode.IsExpanded = false; | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
rootNode.IsExpanded = true; | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
var child1NodeAfter = (TreeViewItem)SUT.FindName("Child 1"); | ||
Assert.IsNotNull(child1NodeAfter); | ||
|
||
Assert.AreEqual("Child 1", child1NodeAfter.Content); | ||
|
||
var child2NodeAfter = (TreeViewItem)SUT.FindName("Child 2"); | ||
Assert.IsNotNull(child2NodeAfter); | ||
|
||
Assert.AreEqual("Child 2", child2NodeAfter.Content); | ||
} | ||
|
||
private class MyNode | ||
{ | ||
public string Name { get; set; } | ||
public List<MyNode> Children { get; set; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...o.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/TreeViewTests/When_Open_Close_Twice.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,21 @@ | ||
<Grid x:Class="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.TreeViewTests.When_Open_Close_Twice" | ||
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.TreeViewTests" | ||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<muxc:TreeView x:Name="myTree" x:FieldModifier="public" SelectionMode="Multiple" | ||
ItemsSource="{Binding Children}"> | ||
<muxc:TreeView.ItemTemplate> | ||
<DataTemplate> | ||
<muxc:TreeViewItem ItemsSource="{Binding Children}" | ||
Content="{Binding Name}" | ||
Name="{Binding Name}" /> | ||
</DataTemplate> | ||
</muxc:TreeView.ItemTemplate> | ||
</muxc:TreeView> | ||
</Grid> |
24 changes: 24 additions & 0 deletions
24
...I.RuntimeTests/Tests/Windows_UI_Xaml_Controls/TreeViewTests/When_Open_Close_Twice.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,24 @@ | ||
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; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.TreeViewTests; | ||
|
||
public sealed partial class When_Open_Close_Twice : Grid | ||
{ | ||
public When_Open_Close_Twice() | ||
{ | ||
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