|
20 | 20 | #endif |
21 | 21 |
|
22 | 22 | using ItemsRepeater = Microsoft.UI.Xaml.Controls.ItemsRepeater; |
| 23 | +using Layout = Microsoft.UI.Xaml.Controls.Layout; |
23 | 24 | using ItemsSourceView = Microsoft.UI.Xaml.Controls.ItemsSourceView; |
24 | 25 | using RecyclingElementFactory = Microsoft.UI.Xaml.Controls.RecyclingElementFactory; |
25 | 26 | using RecyclePool = Microsoft.UI.Xaml.Controls.RecyclePool; |
@@ -267,52 +268,63 @@ public void NestedRepeaterWithDataTemplateScenario() |
267 | 268 | [TestMethod] |
268 | 269 | public void VerifyFocusedItemIsRecycledOnCollectionReset() |
269 | 270 | { |
270 | | - List<string> items = new List<string> { "item0", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9" }; |
271 | | - ItemsRepeater repeater = null; |
272 | | - const int targetIndex = 4; |
273 | | - string targetItem = items[targetIndex]; |
274 | | - |
| 271 | + List<Layout> layouts = new List<Layout>(); |
275 | 272 | RunOnUIThread.Execute(() => |
276 | 273 | { |
277 | | - repeater = new ItemsRepeater() { |
278 | | - ItemsSource = items, |
279 | | - ItemTemplate = CreateDataTemplateWithContent(@"<Button Content='{Binding}'/>") |
280 | | - }; |
281 | | - Content = repeater; |
| 274 | + layouts.Add(new MyCustomNonVirtualizingStackLayout()); |
| 275 | + layouts.Add(new StackLayout()); |
282 | 276 | }); |
283 | | - |
284 | | - IdleSynchronizer.Wait(); |
285 | 277 |
|
286 | | - RunOnUIThread.Execute(() => |
| 278 | + foreach (var layout in layouts) |
287 | 279 | { |
288 | | - Log.Comment("Setting Focus on item " + targetIndex); |
289 | | - Button toFocus = (Button)repeater.TryGetElement(targetIndex); |
290 | | - Verify.AreEqual(targetItem, toFocus.Content as string); |
291 | | - toFocus.Focus(FocusState.Keyboard); |
292 | | - }); |
| 280 | + List<string> items = new List<string> { "item0", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9" }; |
| 281 | + const int targetIndex = 4; |
| 282 | + string targetItem = items[targetIndex]; |
| 283 | + ItemsRepeater repeater = null; |
293 | 284 |
|
294 | | - IdleSynchronizer.Wait(); |
| 285 | + RunOnUIThread.Execute(() => |
| 286 | + { |
| 287 | + repeater = new ItemsRepeater() { |
| 288 | + ItemsSource = items, |
| 289 | + ItemTemplate = CreateDataTemplateWithContent(@"<Button Content='{Binding}'/>"), |
| 290 | + Layout = layout |
| 291 | + }; |
| 292 | + Content = repeater; |
| 293 | + }); |
295 | 294 |
|
296 | | - RunOnUIThread.Execute(() => |
297 | | - { |
298 | | - Log.Comment("Removing focused element from collection"); |
299 | | - items.Remove(targetItem); |
| 295 | + IdleSynchronizer.Wait(); |
300 | 296 |
|
301 | | - Log.Comment("Reset the collection with an empty list"); |
302 | | - repeater.ItemsSource = new List<string>() ; |
303 | | - }); |
| 297 | + RunOnUIThread.Execute(() => |
| 298 | + { |
| 299 | + Log.Comment("Setting Focus on item " + targetIndex); |
| 300 | + Button toFocus = (Button)repeater.TryGetElement(targetIndex); |
| 301 | + Verify.AreEqual(targetItem, toFocus.Content as string); |
| 302 | + toFocus.Focus(FocusState.Keyboard); |
| 303 | + }); |
304 | 304 |
|
305 | | - IdleSynchronizer.Wait(); |
| 305 | + IdleSynchronizer.Wait(); |
306 | 306 |
|
307 | | - RunOnUIThread.Execute(() => |
308 | | - { |
309 | | - Log.Comment("Verify new elements"); |
310 | | - for (int i = 0; i < items.Count; i++) |
| 307 | + RunOnUIThread.Execute(() => |
311 | 308 | { |
312 | | - Button currentButton = (Button)repeater.TryGetElement(i); |
313 | | - Verify.IsNull(currentButton); |
314 | | - } |
315 | | - }); |
| 309 | + Log.Comment("Removing focused element from collection"); |
| 310 | + items.Remove(targetItem); |
| 311 | + |
| 312 | + Log.Comment("Reset the collection with an empty list"); |
| 313 | + repeater.ItemsSource = new List<string>(); |
| 314 | + }); |
| 315 | + |
| 316 | + IdleSynchronizer.Wait(); |
| 317 | + |
| 318 | + RunOnUIThread.Execute(() => |
| 319 | + { |
| 320 | + Log.Comment("Verify new elements"); |
| 321 | + for (int i = 0; i < items.Count; i++) |
| 322 | + { |
| 323 | + Button currentButton = (Button)repeater.TryGetElement(i); |
| 324 | + Verify.IsNull(currentButton); |
| 325 | + } |
| 326 | + }); |
| 327 | + } |
316 | 328 | } |
317 | 329 |
|
318 | 330 | private DataTemplate CreateDataTemplateWithContent(string content) |
|
0 commit comments