我有一个带有飞进菜单的移动的应用程序,我想折叠和展开一些项目,但不是全部。我尝试了一下listview的展开功能,但只能展开和折叠列表中的所有项目。
我的模型如下所示:
public enum MenuItemType
{
Home,
Offers,
Assortment,
Cart,
Wishlists,
Orders,
ProductCombinations,
Cases,
UserProfile,
UserNotifications,
Sustainability,
OurStores,
AppOverview
}
public class NavMenuItem
{
public MenuItemType Id { get; set; }
public string Title { get; set; }
public string IconSource { get; set; }
public string Group { get; set; }
public ImageSource Image => ImageSource.FromResource(string.Format("EY365OCMobileApp.Images.{0}", IconSource));
}
我在此添加的菜单项:
menuItems = new List<NavMenuItem>
{
new NavMenuItem {Id = MenuItemType.Home, Title="Home", IconSource="homeicon.png" },
new NavMenuItem {Id = MenuItemType.Offers, Title="Offerings", IconSource = "offeringsicon.png", Group = "Shopping"},
new NavMenuItem {Id = MenuItemType.Assortment, Title="Assortment", IconSource = "assortmenticon.png" },
new NavMenuItem {Id = MenuItemType.Cart, Title="Your Cart", IconSource = "carticon.png", Group = "Shopping" },
new NavMenuItem {Id = MenuItemType.Orders, Title="Your Orders", IconSource = "yourordericon.png", Group = "Shopping"},
new NavMenuItem {Id = MenuItemType.Wishlists, Title="Your Wishlists", IconSource = "wishlisticon.png", Group = "Shopping"},
new NavMenuItem {Id = MenuItemType.ProductCombinations, Title="Product Combinations", IconSource="combinations.png", Group = "Shopping"},
new NavMenuItem {Id = MenuItemType.Cases, Title="Your Questions", IconSource = "questionsproblemsicon.png"},
new NavMenuItem {Id = MenuItemType.UserProfile, Title="Your Profile", IconSource="yourprofileicon.png" },
new NavMenuItem {Id = MenuItemType.UserNotifications, Title="Your Notifications", IconSource="notification.png"},
new NavMenuItem {Id = MenuItemType.Sustainability, Title="Sustainability", IconSource="sustainability.png"},
new NavMenuItem {Id = MenuItemType.OurStores, Title="Our Stores", IconSource="store.png"},
new NavMenuItem {Id = MenuItemType.AppOverview, Title="App Overview", IconSource="appoverview.png"},
};
ListViewMenu.ItemsSource = menuItems;
我的列表视图是这样的:
<ListView x:Name="ListViewMenu"
HasUnevenRows="True"
HorizontalOptions="Start"
GroupDisplayBinding="{Binding Group}"
IsGroupingEnabled="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame HasShadow="True"
CornerRadius="10"
BorderColor="#282828"
Padding="1">
<StackLayout>
<Grid Padding="10" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"/>
<ColumnDefinition Width="0.8*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding Image}" Grid.Column="0" WidthRequest="30" HeightRequest="30"/>
<Label Text="{Binding Title}" FontSize="Small" Grid.Column="1" TextColor="black"/>
</Grid>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
我想要的是,有组的项目应该是组,但其他没有组的项目不应该是组。
有办法做到这一点吗?
1条答案
按热度按时间iugsix8n1#
我自己找到了解决方法:我正在询问列表视图行的ID,如果它符合应该展开或折叠的行,我将用额外的行重新加载列表视图。也许有人遇到了同样的问题。下面是我的代码: