public ImageCellListPage() { Title = "ImageCell List Gallery - Legacy"; if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet) { Padding = new Thickness(0, 0, 0, 60); } var dataTemplate = new DataTemplate(typeof(ImageCell)); var stringToImageSourceConverter = new GenericValueConverter( obj => new FileImageSource { File = (string)obj } ); dataTemplate.SetBinding(TextCell.TextProperty, new Binding("Text")); dataTemplate.SetBinding(TextCell.TextColorProperty, new Binding("TextColor")); dataTemplate.SetBinding(TextCell.DetailProperty, new Binding("Detail")); dataTemplate.SetBinding(TextCell.DetailColorProperty, new Binding("DetailColor")); dataTemplate.SetBinding(ImageCell.ImageSourceProperty, new Binding("Image", converter: stringToImageSourceConverter)); Random rand = new Random(250); var albums = new[] { "crimsonsmall.jpg", "oasissmall.jpg", "cover1small.jpg" }; var label = new Label { Text = "I have not been selected" }; var listView = new ListView { AutomationId = CellTypeList.CellTestContainerId, ItemsSource = Enumerable.Range(0, 100).Select(i => new ImageCellTest { Text = "Text " + i, TextColor = i % 2 == 0 ? Color.Red : Color.Blue, Detail = "Detail " + i, DetailColor = i % 2 == 0 ? Color.Red : Color.Blue, Image = albums[rand.Next(0, 3)] }), ItemTemplate = dataTemplate }; listView.ItemSelected += (sender, args) => label.Text = "I was selected"; Content = new StackLayout { Children = { label, listView } }; }
public UrlImageCellListPage() { if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet) { Padding = new Thickness(0, 0, 0, 60); } var dataTemplate = new DataTemplate(typeof(ImageCell)); var stringToImageSourceConverter = new GenericValueConverter( obj => new UriImageSource() { Uri = new Uri((string)obj) }); dataTemplate.SetBinding(TextCell.TextProperty, new Binding("Text")); dataTemplate.SetBinding(TextCell.TextColorProperty, new Binding("TextColor")); dataTemplate.SetBinding(TextCell.DetailProperty, new Binding("Detail")); dataTemplate.SetBinding(TextCell.DetailColorProperty, new Binding("DetailColor")); dataTemplate.SetBinding(ImageCell.ImageSourceProperty, new Binding("Image", converter: stringToImageSourceConverter)); var albums = new List <string>(); for (int i = 0; i < 30; i++) { albums.Add(string.Format("https://raw.githubusercontent.com/xamarin/Xamarin.Forms/main/Microsoft.Maui.Controls.ControlGallery/coffee.png?ticks={0}", i)); } var random = new Random(); var label = new Label { Text = "I have not been selected" }; var listView = new ListView { AutomationId = "ImageUrlCellListView", ItemsSource = Enumerable.Range(0, 300).Select(i => new ImageCellTest { Text = "Text " + i, TextColor = i % 2 == 0 ? Color.Red : Color.Blue, Detail = "Detail " + i, DetailColor = i % 2 == 0 ? Color.Red : Color.Blue, Image = albums[random.Next(0, albums.Count - 1)] }), ItemTemplate = dataTemplate }; listView.ItemSelected += (sender, args) => label.Text = "I was selected"; Content = new StackLayout { Children = { label, listView } }; }
public UrlImageViewCellListPage() { if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet) { Padding = new Thickness(0, 0, 0, 60); } var stringToImageSourceConverter = new GenericValueConverter( obj => new UriImageSource() { Uri = new Uri((string)obj) }); var dataTemplate = new DataTemplate(() => { var cell = new ViewCell(); var image = new Image(); image.SetBinding(Image.SourceProperty, new Binding("Image", converter: stringToImageSourceConverter)); image.WidthRequest = 160; image.HeightRequest = 160; var text = new Label(); text.SetBinding(Label.TextProperty, new Binding("Text")); text.SetBinding(Label.TextColorProperty, new Binding("TextColor")); cell.View = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { image, text } }; return(cell); }); var albums = new string[25]; for (int n = 0; n < albums.Length; n++) { albums[n] = string.Format( "https://raw.githubusercontent.com/xamarin/Xamarin.Forms/main/Microsoft.Maui.Controls.ControlGallery/coffee.png?ticks={0}", n); } var label = new Label { Text = "I have not been selected" }; var listView = new ListView { AutomationId = CellTypeList.CellTestContainerId, ItemsSource = Enumerable.Range(0, albums.Length).Select(i => new UrlImageViewCellListPageModel { Text = "Text " + i, TextColor = i % 2 == 0 ? Color.Red : Color.Blue, Image = albums[i] }), ItemTemplate = dataTemplate }; listView.ItemSelected += (sender, args) => label.Text = "I was selected"; Content = new StackLayout { Children = { label, listView } }; }