Hello,
Is it possible to get BtnName as list in MeasureType class and bind like this in xaml {Binding BtnName[0]} ?
No, it is no possible to do it in DataTemplate
.
You could use CarouselView
with a nested Grid CollectionView
to implement the UI you shared, please refer to the following code:
Step 1. Modify the MeasureType.
public class MeasureType
{
public ObservableCollection<ButtonProperties> buttonProperties { get; set; }
public MeasureType()
{
buttonProperties = new ObservableCollection<ButtonProperties>();
}
public void AddItem(ButtonProperties Properties)
{
buttonProperties.Add(Properties);
}
}
public class ButtonProperties
{
public string BtnName { get; set; }
public bool IsVisible { get; set; }
public ButtonProperties(string name, bool IsVisible)
{
BtnName = name;
this.IsVisible = IsVisible;
}
}
Step 2. Create a ContentView
to show the buttons:
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="this"
x:Class="App2.Views.GridCollection">
<ContentView.Content>
<CollectionView ItemsSource="{Binding buttonProperties}" ItemsLayout="HorizontalGrid, 2">
<CollectionView.ItemTemplate>
<DataTemplate>
<Button Text="{Binding BtnName}" IsVisible="{Binding IsVisible}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentView.Content>
</ContentView>
In my sample, I used the simplest style to show it. You could refer to Horizontal grid to get more details about how to set the horizontal grid.
Step 3. Use the CollectionView
in the CarouselViewPage
:
<CarouselView ItemsSource="{Binding MeasureTypes}" >
<CarouselView.ItemTemplate>
<DataTemplate>
<views:GridCollection/>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.