I use expander for bindable stacklayout items. I want scrollview inside my Expander, How to achieve that?
I use expander for bindable stacklayout items. I want scrollview inside my Expander, How to achieve that?
Hi DesaiMayankKumar-9056,
Welcome to our Microsoft Q&A platform!
You can use the expander provided by Xamarin Community Toolkit. Here is the document you can refer to: Xamarin Community Toolkit Expander.
Here is a simple demo with data binding.
xaml:
<ContentPage.BindingContext>
<local:MainPageViewModel/>
</ContentPage.BindingContext>
<StackLayout>
<xct:Expander>
<xct:Expander.Header>
<Label Text="{Binding ExpanderName}"
FontAttributes="Bold"
FontSize="Medium" />
</xct:Expander.Header>
<ScrollView HeightRequest="200" BackgroundColor="Red">
<StackLayout>
<Label Text="Hello World" HeightRequest="100"/>
<Button Text="Test Button" HeightRequest="100"/>
<ListView ItemsSource="{Binding Students}" VerticalOptions="EndAndExpand"
HasUnevenRows="True" HeightRequest="100">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Name}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ScrollView>
</xct:Expander>
</StackLayout>
viewmodel:
class MainPageViewModel
{
public string ExpanderName { get; }
public List<Student> Students { get; }
public MainPageViewModel()
{
ExpanderName = "Test Expander";
Students = new List<Student>();
for (int i = 0; i < 10; i++)
{
Students.Add(new Student { Name = $"Name{i}" });
}
}
}
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
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.
9 people are following this question.