@@ -63,8 +63,11 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
6363 for ( int i = 0 ; i < children . Count ( ) ; i ++ )
6464 {
6565 var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
66- Assert . AreEqual ( expected [ i ] . u , transform . X ) ;
67- Assert . AreEqual ( expected [ i ] . v , transform . Y ) ;
66+ Assert . AreEqual ( expected [ i ] . u , transform . X , $ "Child { i } not in expected X location.") ;
67+ Assert . AreEqual ( expected [ i ] . v , transform . Y , $ "Child { i } not in expected Y location.") ;
68+
69+ Assert . AreEqual ( 100 , children [ i ] . ActualWidth , $ "Child { i } not of expected width.") ;
70+ Assert . AreEqual ( 50 , children [ i ] . ActualHeight , $ "Child { i } not of expected height.") ;
6871 }
6972 } ) ;
7073 }
@@ -113,8 +116,223 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
113116 for ( int i = 0 ; i < children . Count ( ) ; i ++ )
114117 {
115118 var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
116- Assert . AreEqual ( expected [ i ] . u , transform . X ) ;
117- Assert . AreEqual ( expected [ i ] . v , transform . Y ) ;
119+ Assert . AreEqual ( expected [ i ] . u , transform . X , $ "Child { i } not in expected X location.") ;
120+ Assert . AreEqual ( expected [ i ] . v , transform . Y , $ "Child { i } not in expected Y location.") ;
121+
122+ Assert . AreEqual ( 100 , children [ i ] . ActualWidth , $ "Child { i } not of expected width.") ;
123+ Assert . AreEqual ( 50 , children [ i ] . ActualHeight , $ "Child { i } not of expected height.") ;
124+ }
125+ } ) ;
126+ }
127+
128+ [ TestCategory ( "WrapPanel" ) ]
129+ [ TestMethod ]
130+ public async Task Test_WrapPanel_Normal_Horizontal_WithSpacing ( )
131+ {
132+ await App . DispatcherQueue . EnqueueAsync ( async ( ) =>
133+ {
134+ var treeRoot = XamlReader . Load ( @"<Page
135+ xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
136+ xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
137+ xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
138+ <controls:WrapPanel x:Name=""WrapPanel"" HorizontalSpacing=""10"">
139+ <Border Width=""100"" Height=""50""/>
140+ <Border Width=""100"" Height=""50""/>
141+ <Border Width=""100"" Height=""50""/>
142+ </controls:WrapPanel>
143+ </Page>" ) as FrameworkElement ;
144+
145+ var expected = new ( int u , int v ) [ ]
146+ {
147+ ( 0 , 0 ) ,
148+ ( 110 , 0 ) ,
149+ ( 220 , 0 ) ,
150+ } ;
151+
152+ Assert . IsNotNull ( treeRoot , "Could not load XAML tree." ) ;
153+
154+ // Initialize Visual Tree
155+ await SetTestContentAsync ( treeRoot ) ;
156+
157+ var panel = treeRoot . FindChild ( "WrapPanel" ) as WrapPanel ;
158+
159+ Assert . IsNotNull ( panel , "Could not find WrapPanel in tree." ) ;
160+
161+ // Force Layout calculations
162+ panel . UpdateLayout ( ) ;
163+
164+ var children = panel . Children . Select ( item => item as FrameworkElement ) . ToArray ( ) ;
165+
166+ Assert . AreEqual ( 3 , panel . Children . Count ) ;
167+
168+ // Check all children are in expected places.
169+ for ( int i = 0 ; i < children . Count ( ) ; i ++ )
170+ {
171+ var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
172+ Assert . AreEqual ( expected [ i ] . u , transform . X , $ "Child { i } not in expected X location.") ;
173+ Assert . AreEqual ( expected [ i ] . v , transform . Y , $ "Child { i } not in expected Y location.") ;
174+
175+ Assert . AreEqual ( 100 , children [ i ] . ActualWidth , $ "Child { i } not of expected width.") ;
176+ Assert . AreEqual ( 50 , children [ i ] . ActualHeight , $ "Child { i } not of expected height.") ;
177+ }
178+ } ) ;
179+ }
180+
181+ [ TestCategory ( "WrapPanel" ) ]
182+ [ TestMethod ]
183+ public async Task Test_WrapPanel_Normal_Vertical_WithSpacing ( )
184+ {
185+ await App . DispatcherQueue . EnqueueAsync ( async ( ) =>
186+ {
187+ var treeRoot = XamlReader . Load ( @"<Page
188+ xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
189+ xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
190+ xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
191+ <controls:WrapPanel x:Name=""WrapPanel"" Orientation=""Vertical"" VerticalSpacing=""10"">
192+ <Border Width=""100"" Height=""50""/>
193+ <Border Width=""100"" Height=""50""/>
194+ <Border Width=""100"" Height=""50""/>
195+ </controls:WrapPanel>
196+ </Page>" ) as FrameworkElement ;
197+
198+ var expected = new ( int u , int v ) [ ]
199+ {
200+ ( 0 , 0 ) ,
201+ ( 0 , 60 ) ,
202+ ( 0 , 120 ) ,
203+ } ;
204+
205+ Assert . IsNotNull ( treeRoot , "Could not load XAML tree." ) ;
206+
207+ // Initialize Visual Tree
208+ await SetTestContentAsync ( treeRoot ) ;
209+
210+ var panel = treeRoot . FindChild ( "WrapPanel" ) as WrapPanel ;
211+
212+ Assert . IsNotNull ( panel , "Could not find WrapPanel in tree." ) ;
213+
214+ // Force Layout calculations
215+ panel . UpdateLayout ( ) ;
216+
217+ var children = panel . Children . Select ( item => item as FrameworkElement ) . ToArray ( ) ;
218+
219+ Assert . AreEqual ( 3 , panel . Children . Count ) ;
220+
221+ // Check all children are in expected places.
222+ for ( int i = 0 ; i < children . Count ( ) ; i ++ )
223+ {
224+ var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
225+ Assert . AreEqual ( expected [ i ] . u , transform . X , $ "Child { i } not in expected X location.") ;
226+ Assert . AreEqual ( expected [ i ] . v , transform . Y , $ "Child { i } not in expected Y location.") ;
227+
228+ Assert . AreEqual ( 100 , children [ i ] . ActualWidth , $ "Child { i } not of expected width.") ;
229+ Assert . AreEqual ( 50 , children [ i ] . ActualHeight , $ "Child { i } not of expected height.") ;
230+ }
231+ } ) ;
232+ }
233+
234+ [ TestCategory ( "WrapPanel" ) ]
235+ [ TestMethod ]
236+ public async Task Test_WrapPanel_Normal_Horizontal_WithSpacing_AndPadding ( )
237+ {
238+ await App . DispatcherQueue . EnqueueAsync ( async ( ) =>
239+ {
240+ var treeRoot = XamlReader . Load ( @"<Page
241+ xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
242+ xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
243+ xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
244+ <controls:WrapPanel x:Name=""WrapPanel"" HorizontalSpacing=""10"" Padding=""20"">
245+ <Border Width=""100"" Height=""50""/>
246+ <Border Width=""100"" Height=""50""/>
247+ <Border Width=""100"" Height=""50""/>
248+ </controls:WrapPanel>
249+ </Page>" ) as FrameworkElement ;
250+
251+ var expected = new ( int u , int v ) [ ]
252+ {
253+ ( 20 , 20 ) ,
254+ ( 130 , 20 ) ,
255+ ( 240 , 20 ) ,
256+ } ;
257+
258+ Assert . IsNotNull ( treeRoot , "Could not load XAML tree." ) ;
259+
260+ // Initialize Visual Tree
261+ await SetTestContentAsync ( treeRoot ) ;
262+
263+ var panel = treeRoot . FindChild ( "WrapPanel" ) as WrapPanel ;
264+
265+ Assert . IsNotNull ( panel , "Could not find WrapPanel in tree." ) ;
266+
267+ // Force Layout calculations
268+ panel . UpdateLayout ( ) ;
269+
270+ var children = panel . Children . Select ( item => item as FrameworkElement ) . ToArray ( ) ;
271+
272+ Assert . AreEqual ( 3 , panel . Children . Count ) ;
273+
274+ // Check all children are in expected places.
275+ for ( int i = 0 ; i < children . Count ( ) ; i ++ )
276+ {
277+ var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
278+ Assert . AreEqual ( expected [ i ] . u , transform . X , $ "Child { i } not in expected X location.") ;
279+ Assert . AreEqual ( expected [ i ] . v , transform . Y , $ "Child { i } not in expected Y location.") ;
280+
281+ Assert . AreEqual ( 100 , children [ i ] . ActualWidth , $ "Child { i } not of expected width.") ;
282+ Assert . AreEqual ( 50 , children [ i ] . ActualHeight , $ "Child { i } not of expected height.") ;
283+ }
284+ } ) ;
285+ }
286+
287+ [ TestCategory ( "WrapPanel" ) ]
288+ [ TestMethod ]
289+ public async Task Test_WrapPanel_Normal_Vertical_WithSpacing_AndPadding ( )
290+ {
291+ await App . DispatcherQueue . EnqueueAsync ( async ( ) =>
292+ {
293+ var treeRoot = XamlReader . Load ( @"<Page
294+ xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
295+ xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
296+ xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
297+ <controls:WrapPanel x:Name=""WrapPanel"" Orientation=""Vertical"" VerticalSpacing=""10"" Padding=""20"">
298+ <Border Width=""100"" Height=""50""/>
299+ <Border Width=""100"" Height=""50""/>
300+ <Border Width=""100"" Height=""50""/>
301+ </controls:WrapPanel>
302+ </Page>" ) as FrameworkElement ;
303+
304+ var expected = new ( int u , int v ) [ ]
305+ {
306+ ( 20 , 20 ) ,
307+ ( 20 , 80 ) ,
308+ ( 20 , 140 ) ,
309+ } ;
310+
311+ Assert . IsNotNull ( treeRoot , "Could not load XAML tree." ) ;
312+
313+ // Initialize Visual Tree
314+ await SetTestContentAsync ( treeRoot ) ;
315+
316+ var panel = treeRoot . FindChild ( "WrapPanel" ) as WrapPanel ;
317+
318+ Assert . IsNotNull ( panel , "Could not find WrapPanel in tree." ) ;
319+
320+ // Force Layout calculations
321+ panel . UpdateLayout ( ) ;
322+
323+ var children = panel . Children . Select ( item => item as FrameworkElement ) . ToArray ( ) ;
324+
325+ Assert . AreEqual ( 3 , panel . Children . Count ) ;
326+
327+ // Check all children are in expected places.
328+ for ( int i = 0 ; i < children . Count ( ) ; i ++ )
329+ {
330+ var transform = treeRoot . CoordinatesTo ( children [ i ] ) ;
331+ Assert . AreEqual ( expected [ i ] . u , transform . X , $ "Child { i } not in expected X location.") ;
332+ Assert . AreEqual ( expected [ i ] . v , transform . Y , $ "Child { i } not in expected Y location.") ;
333+
334+ Assert . AreEqual ( 100 , children [ i ] . ActualWidth , $ "Child { i } not of expected width.") ;
335+ Assert . AreEqual ( 50 , children [ i ] . ActualHeight , $ "Child { i } not of expected height.") ;
118336 }
119337 } ) ;
120338 }
0 commit comments