I'm trying to implement a treeview with nested data in Xamarin forms. Something that looks like this
Tapping on each item opens a list of possible sub items. The examples I've seen online only deal with one layer of data using a ListView. Is it possible to implement such hierarchical view of data in xamarin forms.
<ListView x:Name="GroupedView" GroupDisplayBinding="{Binding Header}" RowHeight="75" IsGroupingEnabled="True" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout HeightRequest="{Binding height}">
<Label Text="{Binding MenuText}" TextColor="Green" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Label.GestureRecognizers>
</Label>
<ScrollView>
<ListView ItemsSource="{Binding submenuitems}" HasUnevenRows="True" IsVisible="{Binding expand}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="25,5,5,5" HeightRequest="{Binding height}">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped_1"/>
</StackLayout.GestureRecognizers>
<Label Text="{Binding MenuText}" TextColor="DarkBlue"/>
<ScrollView>
<ListView ItemsSource="{Binding submenuitems_2}" HasUnevenRows="True" IsVisible="{Binding expand}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell >
<StackLayout Margin="35,10,5,5" HeightRequest="45">
<Label Text="{Binding MenuText}" TextColor="Red"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5,5,5,5" BackgroundColor="#E2F5F9">
<Button Image="{Binding StateIcon}" BackgroundColor="Transparent" BorderColor="Transparent" BorderWidth="0" Clicked="HeaderTapped" CommandParameter="{Binding .}"/>
<Label Text="{Binding Header}" TextColor="#005569" FontSize="15" VerticalOptions="Center"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
</ListView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With