That is roughly the problem I have.
Here is the code:
<CollectionView x:Name="colview" VerticalScrollBarVisibility="Never" HorizontalScrollBarVisibility="Never" RemainingItemsThreshold="5"> <CollectionView.ItemsLayout> <GridItemsLayout Orientation="Horizontal"/> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid > <Grid.RowDefinitions> <RowDefinition Height="160"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"/> </Grid.ColumnDefinitions> <Label Text="{Binding name}" BackgroundColor="{Binding backcol}" FontSize="20" FontAttributes="Bold" WidthRequest="100" Margin="0,0,0,2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="0" Grid.Row="0"/> <ListView ItemsSource="{Binding listtimes}" HasUnevenRows="False" SelectionMode="None" SeparatorVisibility="None" VerticalScrollBarVisibility="Never" HorizontalScrollBarVisibility="Never" CachingStrategy="RecycleElementAndDataTemplate" Scrolled="ListView_Scrolled" Grid.Column="0" Grid.Row="1" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Label Text="{Binding time, StringFormat='{}{0:H\\:mm}'}" BackgroundColor="{Binding backgr}" FontSize="15" WidthRequest="100" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView>
Yep, t's a CollectionView loaded by bindings. To make it short, we give it a collection of objects (let's call them "points", if you will) with 3 properties: "name" (string) "listtimes" (list) and "backcol" (another string). We then bind the property "name" to a label and "listtimes" to a ListView (this is where things get confusing). "listtimes" is another list of objects (call 'em "times") with their own variables: "time" (DateTime) and "backgr" (string). Both "backcol" and "backgr" are Hex codes for the background color of each label.
In the CS part of the code we do this:
List<point> points = new List<point>([all data goes here]); colview.ItemsSource = points;
and the rest is binding...
As you can see, the ListViews have a "Scrolled" property, but we are unable to access the other lists in order to, when one is scrolled, scroll the rest equally. I know this sound ridiculous but, hey, I can't contradict my higher-ups! That's what they want and that's what I'm asking.
Thank you very much and apologies for this mess.
Best regards.
P.S.: Some of the ListViews may not have the same amount of lines. In fact a handful of them might have so few items that cannot scroll. Sooo yeah...
Answers
I cannot achieve it by your layout design. However, based on your layout design, I think
Xamarin.Forms.DataGrid
nuget package is suitable for your needs.https://github.com/akgulebubekir/Xamarin.Forms.DataGrid
First of all, Here is a running GIF that used
Xamarin.Forms.DataGrid
.Here is layout code about use
Xamarin.Forms.DataGrid
nuget package.Here is layout's background code.
Here is Model.cs
Here is viewModel.cs
In the end, do not forget to add
Xamarin.Forms.DataGrid.DataGridComponent.Init();
in yourApp.xaml.cs
@RicardoS Are there any update for this issue? If this above answer is helpful, please accept it, it will help others who have similar issue.
Thank you for your response, @LeonLu
Unfortunately, this object was not what we were looking for on the principle that we obtain the data of our list from an API and have no idea how many columns it has beforehand.
I think that I should have mention that.
Regards
If you use MVVM method, it cannot be achieved about scrolling multiple lists at the same time. Because all of models are independented, they are cannot be scrolled multiple lists at the same time.