【问题标题】:Submenu for a listview of Navigation drawer by using Master detail Page使用主详细信息页面的导航抽屉列表视图的子菜单
【发布时间】:2020-02-11 09:49:35
【问题描述】:

我想在导航抽屉(主详细信息页面)中的列表视图中实现子项目。 我实现了代码,但它不起作用。 请检查下面的 Github 链接以获取我的代码。

https://github.com/priyam1996/NavigationSubMenuProject

public MainPage()
        {
            InitializeComponent();
            NavigationPage.SetHasBackButton(this, false);
            NavigationPage.SetHasNavigationBar(this, false);

            HotelsGroupViewModel viewModel = new HotelsGroupViewModel();
            HotelsList.ItemsSource = viewModel.Items;

            this.IsPresented = false;
            Detail = new NavigationPage(new Dashboard());
        }

【问题讨论】:

    标签: listview xamarin.forms navigation-drawer submenu


    【解决方案1】:
    <StackLayout x:Name="hotelStack" Padding="1,0,1,0" >
                <ListView
                    x:Name="HotelsList"
                    BackgroundColor="White"
                    IsGroupingEnabled="True"
                    IsPullToRefreshEnabled="true"
                    IsRefreshing="{Binding IsBusy, Mode=OneWay}"
                    ItemsSource="{Binding Items}"
                    RefreshCommand="{Binding LoadHotelsCommand}"
                    >
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Orientation="Horizontal"  VerticalOptions="Center">
                                        <Label
                                            VerticalOptions="Center"
                                            FontAttributes="Bold"
                                            FontSize="Medium"
                                            Text="{Binding .RoomName}"
                                            TextColor="Black"
                                            VerticalTextAlignment="Center" />                                  
                                </StackLayout>                                   
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                    <ListView.GroupHeaderTemplate>
                        <DataTemplate>
                            <ViewCell>
                               <Grid >
                                   <Label
                                                FontAttributes="Bold"
                                                FontSize="Small"
                                                Text="{Binding Name}"
                                                TextColor="Gray"
                                                VerticalTextAlignment="Center" />
                                    <Image x:Name="ImgA" Source="{Binding StateIcon}"  Margin="0,0,5,0" HeightRequest="20" WidthRequest="20" HorizontalOptions="End"/>
                                    <Grid.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                    </Grid.GestureRecognizers>
                                </Grid>                               
                            </ViewCell>
                        </DataTemplate>
                    </ListView.GroupHeaderTemplate>
                </ListView>
            </StackLayout>
    

    点击here! 这也有效。

    【讨论】:

    • 出现错误。属性路径语法无效。 ListViewWithSubListView Hotels.xaml 28 未找到与给定名称匹配的资源:attr 'colorPrimaryDark'。检索项目的父项时出错:找不到与给定名称“Theme.AppCompat.Light.Dialog”匹配的资源。
    • 首先,从给定的链接下载repo,然后恢复包并运行项目。
    • 是否还原了软件包..仍然出现相同的错误。
    • 这个样本在我的最后工作正常。您使用的是哪个版本的 Visual Studio 和操作系统?确保软件包已恢复,没有任何网络代理可能是您的网络有防火墙代理。
    • 我正在使用 Visual Studio 2017 版本和 Widows OS。我恢复了包
    猜你喜欢
    • 2017-01-28
    • 1970-01-01
    • 2019-08-23
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多