IsGroupingEnabled =“true”使listview为空

时间:2018-03-22 06:39:23

标签: c# listview xamarin xamarin.forms expandablelistview

我有一个带有listview的现有项目,我想添加一个可扩展的列表视图,所以我遵循了这个指南:https://github.com/my-jabin/ExpandableListView-Xamarin

这是我的列表视图:

 <ListView
            IsGroupingEnabled="true"
            Margin="0"
            ItemsSource="{Binding ItemsSourceListView}"
            Grid.Row="2"
            IsPullToRefreshEnabled="true"
            IsRefreshing="{Binding IsBusy, Mode=OneWay}"
            HasUnevenRows="false"
            RefreshCommand="{Binding Reload}"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand"
            Header="{Binding ShowHeaderObject}"
            Footer="{Binding FooterObject}"
            BackgroundColor="{StaticResource DarkPrimaryColor}"
            SeparatorVisibility="Default"
            CachingStrategy="RecycleElementAndDataTemplate"
            SeparatorColor="{StaticResource LightSeparator}"
            RowHeight="140"
            ItemTemplate="{StaticResource ListViewTemplate}">
            <ListView.FooterTemplate>
                <DataTemplate>
                    <StackLayout>
                        <Label
                            Text="{Binding .}"
                            Margin="20"
                            HorizontalTextAlignment="Center"
                            TextColor="White" />
                    </StackLayout>
                </DataTemplate>
            </ListView.FooterTemplate>
            <ListView.HeaderTemplate>
                <DataTemplate>
                    <StackLayout>
                        <Label
                            Text="{Binding .}"
                            HorizontalTextAlignment="Center"
                            TextColor="White" />
                    </StackLayout>
                </DataTemplate>
            </ListView.HeaderTemplate>
             <ListView.ItemTemplate>
            <DataTemplate>                   
                <ViewCell>
                    <StackLayout Orientation="Horizontal">
                        <Image 
                            Source="{Binding Flag}"
                            BorderColor="White"
                            BorderThickness="2"
                            HeightRequest="75"
                            WidthRequest="65">
                        </Image>
                        <StackLayout HorizontalOptions="FillAndExpand" Spacing="1">
                            <Label Text="{Binding Name}" FontSize="Medium" TextColor="#005569" VerticalOptions="Center" />
                            <Label Text="{Binding Code}" FontSize="Micro" TextColor="#005569" VerticalOptions="Center" />
                        </StackLayout>
                    </StackLayout>                        
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.GroupHeaderTemplate>
            <DataTemplate>
                <ViewCell>
                    <RelativeLayout Padding="16,8,8,16" HorizontalOptions="FillAndExpand" BackgroundColor="#E2F5F9">
                        <Label Text="{Binding Name}"
                           FontSize="Large"
                           RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.1}"
                           RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0, Constant=6}"  />
                        <RelativeLayout.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.HeaderClickCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                        </RelativeLayout.GestureRecognizers>
                    </RelativeLayout>
              </ViewCell>
            </DataTemplate>
        </ListView.GroupHeaderTemplate>
        </ListView>

为了实现可扩展的列表视图,我添加到listview的新代码是这个(也添加了IsGroupingEnabled =“true”):

<ListView.ItemTemplate>
            <DataTemplate>                   
                <ViewCell>
                    <StackLayout Orientation="Horizontal">
                        <controls:CircleImage 
                            Source="{Binding Flag}"
                            BorderColor="White"
                            BorderThickness="2"
                            HeightRequest="75"
                            WidthRequest="65">
                        </controls:CircleImage>
                        <StackLayout HorizontalOptions="FillAndExpand" Spacing="1">
                            <Label Text="{Binding Name}" FontSize="Medium" TextColor="#005569" VerticalOptions="Center" />
                            <Label Text="{Binding Code}" FontSize="Micro" TextColor="#005569" VerticalOptions="Center" />
                        </StackLayout>
                    </StackLayout>                        
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.GroupHeaderTemplate>
            <DataTemplate>
                <ViewCell>
                    <RelativeLayout Padding="16,8,8,16" HorizontalOptions="FillAndExpand">
                        <Label Text="{Binding Name}"
                           FontSize="Large"
                           RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.1}"
                           RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0, Constant=6}"  />
                        <Image x:Name="StateImage" PropertyChanged="StateImage_PropertyChanged"
                           Source="{Binding StateIcon}" 
                           RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.8}"/>
                        <RelativeLayout.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.HeaderClickCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                        </RelativeLayout.GestureRecognizers>
                    </RelativeLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.GroupHeaderTemplate>

在listview上方,我有绑定到listview的网格:

<ResourceDictionary>
        <DataTemplate
            x:Key="ListViewTemplate">

我认为我正在制作的错误出现在列表视图中,而且在XAML方面我并没有超级经验。这个XAML列表视图完全是空白的。我非常感谢能得到的所有帮助。

更新:

当我删除我从可扩展listview指南添加的新代码但保持IsGroupingEnabled =“true”时,listview显示哪个viewmodel是binded的listview。如何使用IsGroupingEnabled =“true”使代码看起来相同?

0 个答案:

没有答案