This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gallery pages for some carouselview bugs (#15250)
* Add gallery pages for changing the itemssource of a carousel view, and hosting a carouselview inside a collecitonview * Expand tests. Co-authored-by: Oliver Brown <oliver_brown2@next.co.uk>
- Loading branch information
1 parent
faaadf8
commit e967c7a
Showing
6 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...rols/GalleryPages/CollectionViewGalleries/CarouselViewGalleries/ReplaceSourceGallery.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ContentPage | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.CarouselViewGalleries.ReplaceSourceGallery"> | ||
<StackLayout> | ||
<CarouselView Loop="False" ItemsSource="{Binding Images}" HeightRequest="200" x:Name="ImageCarousel"> | ||
<CarouselView.ItemTemplate> | ||
<DataTemplate> | ||
<Image Source="{Binding .}" /> | ||
</DataTemplate> | ||
</CarouselView.ItemTemplate> | ||
</CarouselView> | ||
<Label Text="{Binding Position, Source={x:Reference ImageCarousel}}"/> | ||
|
||
<CarouselView Loop="False" ItemsSource="{Binding Colors}" HeightRequest="200" x:Name="ColorCarousel"> | ||
<CarouselView.ItemTemplate> | ||
<DataTemplate> | ||
<BoxView Color="{Binding .}" /> | ||
</DataTemplate> | ||
</CarouselView.ItemTemplate> | ||
</CarouselView> | ||
<Label Text="{Binding Position, Source={x:Reference ColorCarousel}}"/> | ||
|
||
<Button Text="Update BindingContext" Clicked="BindingContextButton_Clicked" /> | ||
<Button Text="Update ItemsSource" Clicked="ItemsSourceButton_Clicked" /> | ||
</StackLayout> | ||
</ContentPage> |
46 changes: 46 additions & 0 deletions
46
...s/GalleryPages/CollectionViewGalleries/CarouselViewGalleries/ReplaceSourceGallery.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.CarouselViewGalleries | ||
{ | ||
public partial class ReplaceSourceGallery : ContentPage | ||
{ | ||
public ReplaceSourceGallery() | ||
{ | ||
InitializeComponent(); | ||
BindingContext = new ViewModel(); | ||
} | ||
|
||
public void BindingContextButton_Clicked(object sender, EventArgs eventArgs) | ||
{ | ||
BindingContext = new ViewModel(); | ||
} | ||
|
||
public void ItemsSourceButton_Clicked(object sender, EventArgs eventArgs) | ||
{ | ||
((ViewModel)BindingContext).Images = CreateImages(); | ||
} | ||
|
||
private static IList<string> CreateImages() => new[] | ||
{ | ||
"cover1.jpg", | ||
"oasis.jpg", | ||
"photo.jpg", | ||
"Vegetables.jpg", | ||
"Fruits.jpg", | ||
"FlowerBuds.jpg", | ||
"Legumes.jpg" | ||
}; | ||
|
||
private static IList<Color> CreateColors() => new[] | ||
{ | ||
Color.Red, Color.Blue, Color.Green | ||
}; | ||
|
||
public class ViewModel | ||
{ | ||
public IList<string> Images { get; set; } = CreateImages(); | ||
public IList<Color> Colors { get; set; } = CreateColors(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...GalleryPages/CollectionViewGalleries/NestedGalleries/CarouselInCollectionViewGallery.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ContentPage | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.NestedGalleries.CarouselInCollectionViewGallery"> | ||
<CollectionView ItemsSource="{Binding Items}"> | ||
<CollectionView.ItemsLayout> | ||
<GridItemsLayout Span="2" Orientation="Vertical" /> | ||
</CollectionView.ItemsLayout> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<StackLayout> | ||
<CarouselView Loop="False" ItemsSource="{Binding Images}" HeightRequest="200" x:Name="Carousel"> | ||
<CarouselView.ItemTemplate> | ||
<DataTemplate> | ||
<Image Source="{Binding .}" /> | ||
</DataTemplate> | ||
</CarouselView.ItemTemplate> | ||
</CarouselView> | ||
<Label Text="{Binding Position, Source={x:Reference Carousel}}"/> | ||
</StackLayout> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
</ContentPage> |
38 changes: 38 additions & 0 deletions
38
...leryPages/CollectionViewGalleries/NestedGalleries/CarouselInCollectionViewGallery.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.NestedGalleries | ||
{ | ||
public partial class CarouselInCollectionViewGallery : ContentPage | ||
{ | ||
public CarouselInCollectionViewGallery() | ||
{ | ||
InitializeComponent(); | ||
BindingContext = new ViewModel(); | ||
} | ||
|
||
public class ViewModel | ||
{ | ||
public List<Item> Items { get; } | ||
|
||
public ViewModel() | ||
{ | ||
Items = Enumerable.Range(0, 30).Select(x => new Item()).ToList(); | ||
} | ||
} | ||
|
||
public class Item | ||
{ | ||
public IList<string> Images { get; set; } = new[] | ||
{ | ||
"cover1.jpg", | ||
"oasis.jpg", | ||
"photo.jpg", | ||
"Vegetables.jpg", | ||
"Fruits.jpg", | ||
"FlowerBuds.jpg", | ||
"Legumes.jpg" | ||
}; | ||
} | ||
} | ||
} |