public void ValidateRecycling() { RunOnUIThread.Execute(() => { var elementFactory = new RecyclingElementFactory() { RecyclePool = new RecyclePool(), }; elementFactory.Templates["even"] = (DataTemplate)XamlReader.Parse( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='even' /> </DataTemplate>"); elementFactory.Templates["odd"] = (DataTemplate)XamlReader.Parse( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='odd' /> </DataTemplate>"); elementFactory.SelectTemplateKey += delegate(RecyclingElementFactory sender, SelectTemplateEventArgs args) { args.TemplateKey = ((int)args.DataContext % 2 == 0) ? "even" : "odd"; }; const int numItems = 10; ItemsRepeater repeater = new ItemsRepeater() { ItemsSource = Enumerable.Range(0, numItems), ItemTemplate = elementFactory, }; var context = (ElementFactoryGetArgs)RepeaterTestHooks.CreateRepeaterElementFactoryGetArgs(); context.Parent = repeater; var clearContext = (ElementFactoryRecycleArgs)RepeaterTestHooks.CreateRepeaterElementFactoryRecycleArgs(); clearContext.Parent = repeater; // Element0 is of type even, a new one should be created context.Data = 0; var element0 = elementFactory.GetElement(context); Verify.IsNotNull(element0); Verify.AreEqual("even", (element0 as TextBlock).Text); clearContext.Element = element0; elementFactory.RecycleElement(clearContext); // Element1 is of type odd, a new one should be created context.Data = 1; var element1 = elementFactory.GetElement(context); Verify.IsNotNull(element1); Verify.AreNotSame(element0, element1); Verify.AreEqual("odd", (element1 as TextBlock).Text); clearContext.Element = element1; elementFactory.RecycleElement(clearContext); // Element0 should be recycled for element2 context.Data = 2; var element2 = elementFactory.GetElement(context); Verify.AreEqual("even", (element2 as TextBlock).Text); Verify.AreSame(element0, element2); // Element1 should be recycled for element3 context.Data = 3; var element3 = elementFactory.GetElement(context); Verify.AreEqual("odd", (element3 as TextBlock).Text); Verify.AreSame(element1, element3); }); }
private void OnElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { var button = args.Element as Button; var result = button.DataContext as InlineQueryResult; var content = button.Content as Grid; if (content.Children[0] is Image image) { _zoomer.ElementPrepared(args.Element); if (result is InlineQueryResultAnimation || result is InlineQueryResultPhoto || result is InlineQueryResultVideo) { File file = null; if (result is InlineQueryResultAnimation animation) { file = animation.Animation.Thumbnail?.File; } else if (result is InlineQueryResultPhoto photo) { file = photo.Photo.GetSmall().Photo; } else if (result is InlineQueryResultVideo video) { file = video.Video.Thumbnail?.File; } if (file == null) { return; } if (file.Local.IsDownloadingCompleted) { image.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { image.Source = null; DownloadFile(_thumbnails, file.Id, result); } } else if (result is InlineQueryResultSticker sticker) { var file = sticker.Sticker.Thumbnail.File; if (file == null) { return; } if (file.Local.IsDownloadingCompleted) { image.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { image.Source = null; DownloadFile(_thumbnails, file.Id, result); } } } else if (content.Children[0] is Grid presenter) { _zoomer.ElementClearing(args.Element); //var presenter = content.Children[0] as Grid; var thumb = presenter.Children[0] as Image; var title = content.Children[1] as TextBlock; var description = content.Children[2] as TextBlock; File file = null; Uri uri = null; if (result is InlineQueryResultArticle article) { file = article.Thumbnail?.File; title.Text = article.Title; description.Text = article.Description; } else if (result is InlineQueryResultAudio audio) { file = audio.Audio.AlbumCoverThumbnail?.File; title.Text = audio.Audio.GetTitle(); description.Text = audio.Audio.GetDuration(); } else if (result is InlineQueryResultContact contact) { file = contact.Thumbnail?.File; title.Text = contact.Contact.GetFullName(); description.Text = PhoneNumber.Format(contact.Contact.PhoneNumber); } else if (result is InlineQueryResultDocument document) { file = document.Document.Thumbnail?.File; title.Text = document.Title; if (string.IsNullOrEmpty(document.Description)) { description.Text = FileSizeConverter.Convert(document.Document.DocumentValue.Size); } else { description.Text = document.Description; } } else if (result is InlineQueryResultGame game) { file = game.Game.Animation?.Thumbnail?.File ?? game.Game.Photo.GetSmall().Photo; title.Text = game.Game.Title; description.Text = game.Game.Description; } else if (result is InlineQueryResultLocation location) { var latitude = location.Location.Latitude.ToString(CultureInfo.InvariantCulture); var longitude = location.Location.Longitude.ToString(CultureInfo.InvariantCulture); uri = new Uri(string.Format("https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{0},{1}/{2}?mapSize={3}&key=FgqXCsfOQmAn9NRf4YJ2~61a_LaBcS6soQpuLCjgo3g~Ah_T2wZTc8WqNe9a_yzjeoa5X00x4VJeeKH48wAO1zWJMtWg6qN-u4Zn9cmrOPcL", latitude, longitude, 15, "96,96")); file = location.Thumbnail?.File; title.Text = location.Title; description.Text = $"{location.Location.Latitude};{location.Location.Longitude}"; } else if (result is InlineQueryResultPhoto photo) { file = photo.Photo.GetSmall().Photo; title.Text = photo.Title; description.Text = photo.Description; } else if (result is InlineQueryResultVenue venue) { var latitude = venue.Venue.Location.Latitude.ToString(CultureInfo.InvariantCulture); var longitude = venue.Venue.Location.Longitude.ToString(CultureInfo.InvariantCulture); uri = new Uri(string.Format("https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{0},{1}/{2}?mapSize={3}&key=FgqXCsfOQmAn9NRf4YJ2~61a_LaBcS6soQpuLCjgo3g~Ah_T2wZTc8WqNe9a_yzjeoa5X00x4VJeeKH48wAO1zWJMtWg6qN-u4Zn9cmrOPcL", latitude, longitude, 15, "96,96")); file = venue.Thumbnail?.File; title.Text = venue.Venue.Title; description.Text = venue.Venue.Address; } else if (result is InlineQueryResultVideo video) { file = video.Video.Thumbnail?.File; title.Text = video.Title; description.Text = video.Description; } else if (result is InlineQueryResultVoiceNote voiceNote) { title.Text = voiceNote.Title; description.Text = voiceNote.VoiceNote.GetDuration(); } if (file != null) { if (file.Local.IsDownloadingCompleted) { thumb.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { thumb.Source = null; DownloadFile(_thumbnails, file.Id, result); } } else if (uri != null) { thumb.Source = new BitmapImage(uri); } else { thumb.Source = PlaceholderHelper.GetNameForChat(title.Text, 96, title.Text.GetHashCode()); } } }
public void VerifyCustomItemTemplate() { Breadcrumb breadcrumb = null; Breadcrumb breadcrumb2 = null; RunOnUIThread.Execute(() => { breadcrumb = new Breadcrumb(); breadcrumb.ItemsSource = new List <string>() { "Node 1", "Node 2" }; // Set a custom ItemTemplate to be wrapped in a BreadcrumbItem. var itemTemplate = (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='{Binding}'/> </DataTemplate>"); breadcrumb.ItemTemplate = itemTemplate; breadcrumb2 = new Breadcrumb(); breadcrumb2.ItemsSource = new List <string>() { "Node 1", "Node 2" }; // Set a custom ItemTemplate which is already a BreadcrumbItem. No wrapping should be performed. var itemTemplate2 = (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:controls='using:Microsoft.UI.Xaml.Controls'> <controls:BreadcrumbItem Foreground='Blue'> <TextBlock Text = '{Binding}'/> </controls:BreadcrumbItem> </DataTemplate>"); breadcrumb2.ItemTemplate = itemTemplate2; var stackPanel = new StackPanel(); stackPanel.Children.Add(breadcrumb); stackPanel.Children.Add(breadcrumb2); Content = stackPanel; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { ItemsRepeater breadcrumbItemsRepeater = (ItemsRepeater)breadcrumb.FindVisualChildByName("PART_ItemsRepeater"); ItemsRepeater breadcrumbItemsRepeater2 = (ItemsRepeater)breadcrumb2.FindVisualChildByName("PART_ItemsRepeater"); Verify.IsNotNull(breadcrumbItemsRepeater, "The underlying items repeater could not be retrieved"); Verify.IsNotNull(breadcrumbItemsRepeater2, "The underlying items repeater could not be retrieved"); var breadcrumbNode1 = breadcrumbItemsRepeater.TryGetElement(1) as BreadcrumbItem; var breadcrumbNode2 = breadcrumbItemsRepeater2.TryGetElement(1) as BreadcrumbItem; Verify.IsNotNull(breadcrumbNode1, "Our custom ItemTemplate should have been wrapped in a BreadcrumbItem."); Verify.IsNotNull(breadcrumbNode2, "Our custom ItemTemplate should have been wrapped in a BreadcrumbItem."); // change this conditions bool testCondition = !(breadcrumbNode1.Foreground is SolidColorBrush brush && brush.Color == Colors.Blue); Verify.IsTrue(testCondition, "Default foreground color of the BreadcrumbItem should not have been [blue]."); testCondition = breadcrumbNode2.Foreground is SolidColorBrush brush2 && brush2.Color == Colors.Blue; Verify.IsTrue(testCondition, "The foreground color of the BreadcrumbItem should have been [blue]."); }); }
public void ValidateDataTemplateSelectorAsItemTemplate() { RunOnUIThread.Execute(() => { var dataTemplateOdd = (DataTemplate)XamlReader.Parse( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='{Binding}' Height='30' /> </DataTemplate>"); var dataTemplateEven = (DataTemplate)XamlReader.Parse( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='{Binding}' Height='40' /> </DataTemplate>"); ItemsRepeater repeater = null; const int numItems = 10; var selector = new MySelector() { TemplateOdd = dataTemplateOdd, TemplateEven = dataTemplateEven }; Content = CreateAndInitializeRepeater ( itemsSource: Enumerable.Range(0, numItems), elementFactory: selector, layout: new StackLayout(), repeater: ref repeater ); Content.UpdateLayout(); Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater)); for (int i = 0; i < numItems; i++) { var element = (TextBlock)repeater.TryGetElement(i); Verify.AreEqual(i.ToString(), element.Text); Verify.AreEqual(i % 2 == 0 ? 40 : 30, element.Height); } repeater.ItemsSource = null; Content.UpdateLayout(); // In versions below RS5 we faked the recycling behaivor on data template // so we can get to the recycle pool that we addded internally in ItemsRepeater. //if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5)) { // All the created items should be in the recycle pool now. var oddPool = RecyclePool.GetPoolInstance(dataTemplateOdd); var oddElements = GetAllElementsFromPool(oddPool); Verify.AreEqual(5, oddElements.Count); foreach (var element in oddElements) { Verify.AreEqual(30, ((TextBlock)element).Height); } var evenPool = RecyclePool.GetPoolInstance(dataTemplateEven); var evenElements = GetAllElementsFromPool(evenPool); Verify.AreEqual(5, evenElements.Count); foreach (var element in evenElements) { Verify.AreEqual(40, ((TextBlock)element).Height); } } }); }
private void Repeater_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { (args.Element as RepeaterItem).RepeatedIndex = args.Index; }
public void VerifyDropdownItemTemplateWithNoControl() { Breadcrumb breadcrumb = null; RunOnUIThread.Execute(() => { breadcrumb = new Breadcrumb(); breadcrumb.ItemsSource = new List <string>() { "Node 1", "Node 2" }; // Set a custom ItemTemplate to be wrapped in a BreadcrumbItem. var itemTemplate = (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='{Binding}'/> </DataTemplate>"); breadcrumb.ItemTemplate = itemTemplate; var stackPanel = new StackPanel(); stackPanel.Width = 60; stackPanel.Children.Add(breadcrumb); Content = stackPanel; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); Button ellipsisButton = null; RunOnUIThread.Execute(() => { ItemsRepeater breadcrumbItemsRepeater = (ItemsRepeater)breadcrumb.FindVisualChildByName("PART_ItemsRepeater"); Verify.IsNotNull(breadcrumbItemsRepeater, "The underlying items repeater (1) could not be retrieved"); var breadcrumbNode1 = breadcrumbItemsRepeater.TryGetElement(0) as BreadcrumbItem; Verify.IsNotNull(breadcrumbNode1, "Our custom ItemTemplate (1) should have been wrapped in a BreadcrumbItem."); ellipsisButton = (Button)breadcrumbNode1.FindVisualChildByName("PART_ItemButton"); Verify.IsNotNull(ellipsisButton, "The ellipsis item (1) could not be retrieved"); var automationPeer = new ButtonAutomationPeer(ellipsisButton); var invokationPattern = automationPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; invokationPattern?.Invoke(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Flyout ellipsisFlyout = (Flyout)ellipsisButton.Flyout; Verify.IsNotNull(ellipsisButton, "The ellipsis flyout (1) could not be retrieved"); ItemsRepeater ellipsisItemsRepeater = (ItemsRepeater)ellipsisFlyout.Content; Verify.IsNotNull(ellipsisItemsRepeater, "The underlying flyout items repeater (1) could not be retrieved"); ellipsisItemsRepeater.Loaded += (object sender, RoutedEventArgs e) => { TextBlock ellipsisNode1 = ellipsisItemsRepeater.TryGetElement(0) as TextBlock; Verify.IsNotNull(ellipsisNode1, "Our flyout ItemTemplate (1) should have been wrapped in a TextBlock."); // change this conditions bool testCondition = !(ellipsisNode1.Foreground is SolidColorBrush brush && brush.Color == Colors.Blue); Verify.IsTrue(testCondition, "Default foreground color of the BreadcrumbItem should not have been [blue]."); }; }); }
public PinnedElementInfo(UIElement element) { PinnedElement = element; VirtualizationInfo = ItemsRepeater.GetVirtualizationInfo(element); }
private void Repeater_ElementIndexChanged(ItemsRepeater sender, ItemsRepeaterElementIndexChangedEventArgs args) { (args.Element as RepeaterItem).RepeatedIndex = args.NewIndex; }
public void ValidateRecycling() { if (PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone4)) { //BUGBUG Bug 19277320: MUX Repeater tests fail on RS5_Release return; } RunOnUIThread.Execute(() => { var elementFactory = new RecyclingElementFactory() { RecyclePool = new RecyclePool(), }; elementFactory.Templates["even"] = (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='even' /> </DataTemplate>"); elementFactory.Templates["odd"] = (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='odd' /> </DataTemplate>"); elementFactory.SelectTemplateKey += delegate(RecyclingElementFactory sender, SelectTemplateEventArgs args) { args.TemplateKey = ((int)args.DataContext % 2 == 0) ? "even" : "odd"; }; const int numItems = 10; ItemsRepeater repeater = new ItemsRepeater() { ItemsSource = Enumerable.Range(0, numItems), #if BUILD_WINDOWS ItemTemplate = (Windows.UI.Xaml.IElementFactory)elementFactory, #else ItemTemplate = elementFactory, #endif }; var context = (ElementFactoryGetArgs)RepeaterTestHooks.CreateRepeaterElementFactoryGetArgs(); context.Parent = repeater; var clearContext = (ElementFactoryRecycleArgs)RepeaterTestHooks.CreateRepeaterElementFactoryRecycleArgs(); clearContext.Parent = repeater; // Element0 is of type even, a new one should be created context.Data = 0; var element0 = elementFactory.GetElement(context); Verify.IsNotNull(element0); Verify.AreEqual("even", (element0 as TextBlock).Text); clearContext.Element = element0; elementFactory.RecycleElement(clearContext); // Element1 is of type odd, a new one should be created context.Data = 1; var element1 = elementFactory.GetElement(context); Verify.IsNotNull(element1); Verify.AreNotSame(element0, element1); Verify.AreEqual("odd", (element1 as TextBlock).Text); clearContext.Element = element1; elementFactory.RecycleElement(clearContext); // Element0 should be recycled for element2 context.Data = 2; var element2 = elementFactory.GetElement(context); Verify.AreEqual("even", (element2 as TextBlock).Text); Verify.AreSame(element0, element2); // Element1 should be recycled for element3 context.Data = 3; var element3 = elementFactory.GetElement(context); Verify.AreEqual("odd", (element3 as TextBlock).Text); Verify.AreSame(element1, element3); }); }
private void OnElementClearing(ItemsRepeater sender, ItemsRepeaterElementClearingEventArgs args) { OutputText.Text += "Element Cleared" + Environment.NewLine; }
private void OnElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { OutputText.Text += args.Index + "Prepared" + Environment.NewLine; }
public void VerifyDropdownItemTemplateWithNoControl() { BreadcrumbBar breadcrumb = null; RunOnUIThread.Execute(() => { breadcrumb = new BreadcrumbBar(); breadcrumb.ItemsSource = new List <string>() { "Node 1", "Node 2" }; // Set a custom ItemTemplate to be wrapped in a BreadcrumbBarItem. var itemTemplate = (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='{Binding}'/> </DataTemplate>"); breadcrumb.ItemTemplate = itemTemplate; var stackPanel = new StackPanel(); stackPanel.Width = 60; stackPanel.Children.Add(breadcrumb); Content = stackPanel; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); Button ellipsisButton = null; RunOnUIThread.Execute(() => { ItemsRepeater breadcrumbItemsRepeater = (ItemsRepeater)breadcrumb.FindVisualChildByName("PART_ItemsRepeater"); Verify.IsNotNull(breadcrumbItemsRepeater, "The underlying items repeater (1) could not be retrieved"); var breadcrumbNode1 = breadcrumbItemsRepeater.TryGetElement(0) as BreadcrumbBarItem; Verify.IsNotNull(breadcrumbNode1, "Our custom ItemTemplate (1) should have been wrapped in a BreadcrumbBarItem."); ellipsisButton = (Button)breadcrumbNode1.FindVisualChildByName("PART_ItemButton"); Verify.IsNotNull(ellipsisButton, "The ellipsis item (1) could not be retrieved"); var automationPeer = new ButtonAutomationPeer(ellipsisButton); var invokationPattern = automationPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; invokationPattern?.Invoke(); }); // GetOpenPopups returns empty list in RS3. The scenario works, this just seems to be a // test/infra issue in RS3, so filtering it out for now. if (PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone3)) { IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { var flyout = VisualTreeHelper.GetOpenPopups(Window.Current).Last(); Verify.IsNotNull(flyout, "Flyout could not be retrieved"); var ellipsisItemsRepeater = TestUtilities.FindDescendents <ItemsRepeater>(flyout).Single(); Verify.IsNotNull(ellipsisItemsRepeater, "The underlying flyout items repeater (1) could not be retrieved"); ellipsisItemsRepeater.Loaded += (object sender, RoutedEventArgs e) => { TextBlock ellipsisNode1 = ellipsisItemsRepeater.TryGetElement(0) as TextBlock; Verify.IsNotNull(ellipsisNode1, "Our flyout ItemTemplate (1) should have been wrapped in a TextBlock."); // change this conditions bool testCondition = !(ellipsisNode1.Foreground is SolidColorBrush brush && brush.Color == Colors.Blue); Verify.IsTrue(testCondition, "Default foreground color of the BreadcrumbBarItem should not have been [blue]."); }; }); } }
private void CarouselRepeater_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) => HorizontalSnapPointsChanged?.Invoke(this, EventArgs.Empty);