1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+ // See the LICENSE file in the project root for more information.
4+
5+ using System . Linq ;
6+ using System . Threading . Tasks ;
7+ using Microsoft . Toolkit . Uwp ;
8+ using Microsoft . Toolkit . Uwp . UI ;
9+ using Microsoft . Toolkit . Uwp . UI . Controls ;
10+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
11+ using Microsoft . VisualStudio . TestTools . UnitTesting . AppContainer ;
12+ using Windows . Foundation ;
13+ using Windows . UI . Xaml ;
14+ using Windows . UI . Xaml . Controls ;
15+ using Windows . UI . Xaml . Markup ;
16+
17+ namespace UnitTests . UI . Controls
18+ {
19+ [ TestClass ]
20+ public class Test_WrapPanel : VisualUITestBase
21+ {
22+ [ TestCategory ( "WrapPanel" ) ]
23+ [ TestMethod ]
24+ public async Task Test_WrapPanel_Normal_Horizontal ( )
25+ {
26+ await App . DispatcherQueue . EnqueueAsync ( async ( ) =>
27+ {
28+ var treeRoot = XamlReader . Load ( @"<Page
29+ xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
30+ xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
31+ xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
32+ <controls:WrapPanel x:Name=""WrapPanel"">
33+ <Border Width=""100"" Height=""50""/>
34+ <Border Width=""100"" Height=""50""/>
35+ <Border Width=""100"" Height=""50""/>
36+ </controls:WrapPanel>
37+ </Page>" ) as FrameworkElement ;
38+
39+ var expected = new ( int u , int v ) [ ]
40+ {
41+ ( 0 , 0 ) ,
42+ ( 100 , 0 ) ,
43+ ( 200 , 0 ) ,
44+ } ;
45+
46+ Assert . IsNotNull ( treeRoot , "Could not load XAML tree." ) ;
47+
48+ // Initialize Visual Tree
49+ await SetTestContentAsync ( treeRoot ) ;
50+
51+ var panel = treeRoot . FindChild ( "WrapPanel" ) as WrapPanel ;
52+
53+ Assert . IsNotNull ( panel , "Could not find WrapPanel in tree." ) ;
54+
55+ // Force Layout calculations
56+ panel . UpdateLayout ( ) ;
57+
58+ var children = panel . Children . Select ( item => item as FrameworkElement ) . ToArray ( ) ;
59+
60+ Assert . AreEqual ( 3 , panel . Children . Count ) ;
61+
62+ // Check all children are in expected places.
63+ for ( int i = 0 ; i < children . Count ( ) ; i ++ )
64+ {
65+ var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
66+ Assert . AreEqual ( expected [ i ] . u , transform . X ) ;
67+ Assert . AreEqual ( expected [ i ] . v , transform . Y ) ;
68+ }
69+ } ) ;
70+ }
71+
72+ [ TestCategory ( "WrapPanel" ) ]
73+ [ TestMethod ]
74+ public async Task Test_WrapPanel_Normal_Vertical ( )
75+ {
76+ await App . DispatcherQueue . EnqueueAsync ( async ( ) =>
77+ {
78+ var treeRoot = XamlReader . Load ( @"<Page
79+ xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
80+ xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
81+ xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
82+ <controls:WrapPanel x:Name=""WrapPanel"" Orientation=""Vertical"">
83+ <Border Width=""100"" Height=""50""/>
84+ <Border Width=""100"" Height=""50""/>
85+ <Border Width=""100"" Height=""50""/>
86+ </controls:WrapPanel>
87+ </Page>" ) as FrameworkElement ;
88+
89+ var expected = new ( int u , int v ) [ ]
90+ {
91+ ( 0 , 0 ) ,
92+ ( 0 , 50 ) ,
93+ ( 0 , 100 ) ,
94+ } ;
95+
96+ Assert . IsNotNull ( treeRoot , "Could not load XAML tree." ) ;
97+
98+ // Initialize Visual Tree
99+ await SetTestContentAsync ( treeRoot ) ;
100+
101+ var panel = treeRoot . FindChild ( "WrapPanel" ) as WrapPanel ;
102+
103+ Assert . IsNotNull ( panel , "Could not find WrapPanel in tree." ) ;
104+
105+ // Force Layout calculations
106+ panel . UpdateLayout ( ) ;
107+
108+ var children = panel . Children . Select ( item => item as FrameworkElement ) . ToArray ( ) ;
109+
110+ Assert . AreEqual ( 3 , panel . Children . Count ) ;
111+
112+ // Check all children are in expected places.
113+ for ( int i = 0 ; i < children . Count ( ) ; i ++ )
114+ {
115+ var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
116+ Assert . AreEqual ( expected [ i ] . u , transform . X ) ;
117+ Assert . AreEqual ( expected [ i ] . v , transform . Y ) ;
118+ }
119+ } ) ;
120+ }
121+ }
122+ }
0 commit comments