question

DesaiMayankKumar-9056 avatar image
0 Votes"
DesaiMayankKumar-9056 asked DesaiMayankKumar-9056 commented

How to put Scrollview inside Expander?

I use expander for bindable stacklayout items. I want scrollview inside my Expander, How to achieve that?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleWang-MSFT avatar image
0 Votes"
KyleWang-MSFT answered DesaiMayankKumar-9056 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @KyleWang-MSFT appreciated your help. thanks

0 Votes 0 ·