gpt4 book ai didi

Xamarin 窗体 TreeView

转载 作者:行者123 更新时间:2023-12-04 15:51:28 24 4
gpt4 key购买 nike

我正在尝试使用 Xamarin 表单中的嵌套数据实现树 View 。看起来像这样的东西
enter image description here

点击每个项目会打开一个可能的子项目列表。我在网上看到的示例仅使用 ListView 处理一层数据。是否可以以 xamarin 形式实现这种数据分层 View 。

最佳答案

<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>

关于Xamarin 窗体 TreeView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48105598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com