public async Task When_ItemTemplateSelector_Set() { var itemsSource = new[] { "item 1", "item 2", "item 3" }; var templateSelector = new KeyedTemplateSelector { Templates = { { itemsSource[0], SelectableItemTemplateA }, { itemsSource[1], SelectableItemTemplateB }, { itemsSource[2], SelectableItemTemplateC }, } }; var list = new ListView { ItemsSource = itemsSource, ItemTemplateSelector = templateSelector }; WindowHelper.WindowContent = list; await WindowHelper.WaitForLoaded(list); var container1 = await WindowHelper.WaitForNonNull(() => list.ContainerFromIndex(0) as ListViewItem); var text1 = container1.FindFirstChild <TextBlock>(tb => tb.Name == "TextBlockInTemplate"); Assert.IsNotNull(text1); Assert.AreEqual(text1.Text, "Selectable A"); var container2 = await WindowHelper.WaitForNonNull(() => list.ContainerFromIndex(1) as ListViewItem); var text2 = container2.FindFirstChild <TextBlock>(tb => tb.Name == "TextBlockInTemplate"); Assert.IsNotNull(text2); Assert.AreEqual(text2.Text, "Selectable B"); var container3 = await WindowHelper.WaitForNonNull(() => list.ContainerFromIndex(2) as ListViewItem); var text3 = container3.FindFirstChild <TextBlock>(tb => tb.Name == "TextBlockInTemplate"); Assert.IsNotNull(text3); Assert.AreEqual(text3.Text, "Selectable C"); }
public async Task When_ContentTemplateSelector_And_Default_Style() { var items = new[] { "item 1", "item 2", "item 3" }; foreach (var control in DerivedStyledControlsInstances) { var templateSelector = new KeyedTemplateSelector { Templates = { { items[0], SelectableItemTemplateA }, { items[1], SelectableItemTemplateB }, { items[2], SelectableItemTemplateC }, } }; control.ContentTemplateSelector = templateSelector; control.Content = "Dummy"; WindowHelper.WindowContent = control; await WindowHelper.WaitForLoaded(control); control.Content = items[0]; var text1 = await WindowHelper.WaitForNonNull(() => control.FindFirstChild <TextBlock>(tb => tb.Name == "TextBlockInTemplate"), message : $"Template selector not applied for {control.GetType()}"); Assert.AreEqual(text1.Text, "Selectable A", $"Template selector not applied for {control.GetType()}"); control.Content = items[1]; var text2 = await WindowHelper.WaitForNonNull(() => control.FindFirstChild <TextBlock>(tb => tb.Name == "TextBlockInTemplate")); Assert.AreEqual(text2.Text, "Selectable B"); control.Content = items[2]; var text3 = await WindowHelper.WaitForNonNull(() => control.FindFirstChild <TextBlock>(tb => tb.Name == "TextBlockInTemplate")); Assert.AreEqual(text3.Text, "Selectable C"); } }