ListView grouping, only groups visible, no items (xamarin.fomrs+prism)

kk_kkk_k PLMember

I've tried to create ListView with grouped list, but only groups shows up in listView, items are not displayed. At first my Model didn't inherit from BindableBase but i had same issue. I've also tried to do this according to @JamesMontemagno
motzcod.es/post/94643411707/enhancing-xamarinforms-listview-with-grouping sample but it was the same. What am i doing wrong?

Model:

public class FilteringOptions : Prism.Mvvm.BindableBase
{
    public ObservableCollection<PageGroups> Groups { get; set; }

    private ObservableCollection<Filter> _filters;
    public ObservableCollection<Filter> Filters
    {
        get { return _filters; }
        set { SetProperty(ref _filters, value); }
    }

    public decimal MaxPrice { get; set; }

    public decimal MinPrice { get; set; }

    public decimal? PriceFrom { get; set; }

    public decimal? PriceTo { get; set; }
}

public class Filter: Prism.Mvvm.BindableBase
{
    public string Field { get; set; }

    public string Heading { get; set; }

    private ObservableCollection<FilterValue> _values;
    public ObservableCollection<FilterValue> Values
    {
        get { return _values; }
        set { SetProperty(ref _values, value); }
    }
}

public class FilterValue : Prism.Mvvm.BindableBase
{
    public int Count { get; set; }

    public int TotalCount { get; set; }

    public bool _selected;
    public bool Selected
    {
        get { return _selected; }
        set { SetProperty(ref _selected, value); }
    }

    public string _text;
    public string Text      {
        get { return _text; }
        set { SetProperty(ref _text, value); }
    }

    public string Field { get; set; }

    public string Value { get; set; }

}

ViewModel:

public class FilterViewViewModel : BaseViewModel
{

    public FilterViewViewModel(INavigationService navigationService, IPageDialogService pageDialogService, INetworkConnectionService networkConnectionService) : base(navigationService, pageDialogService, networkConnectionService)
    {
        Cancel = new DelegateCommand(DoCancel);
        Filter = new DelegateCommand(DoFilter);
    }

    public DelegateCommand Cancel { get; }

    public DelegateCommand Filter { get; }

    public override void OnNavigatedTo(NavigationParameters parameters)
    {
        //if (parameters["filters"] != null)
        //{
        //  FilteringOptions = (FilteringOptions)parameters["filters"];
        //}

        var temp = new FilteringOptions();
        temp.Filters = new ObservableCollection<Models.Filter>();
        temp.Filters.Add(new Models.Filter()
        {
            Heading = "testFilter",
            Field = "testFilter",
            Values = new ObservableCollection<FilterValue>() { new FilterValue() {  Field = "testFilter", Text = "value1", Selected = false },
                                                        new FilterValue() {  Field = "testFilter", Text = "value2", Selected = false },
                                                        new FilterValue() {  Field = "testFilter", Text = "value3", Selected = false },
                                                        new FilterValue() {  Field = "testFilter", Text = "value4", Selected = false }}});
        temp.Filters.Add(new Models.Filter()
        {
            Heading = "testFilter2",
            Field = "testFilter2",
            Values = new ObservableCollection<FilterValue>() { new FilterValue() {  Field = "testFilter2", Text = "value1", Selected = false },
                                                        new FilterValue() {  Field = "testFilter2", Text = "value2", Selected = false },
                                                        new FilterValue() {  Field = "testFilter2", Text = "value3", Selected = false },
                                                        new FilterValue() {  Field = "testFilter2", Text = "value4", Selected = false }}
        });


        FilteringOptions = temp;
    }

    private FilteringOptions _filteringOptions;

    public FilteringOptions FilteringOptions
    {
        get { return _filteringOptions; }
        set { SetProperty(ref _filteringOptions, value); }
    }

    private async void DoCancel()
    {
        await _navigationService.PopupGoBackAsync();
    }

    private async void DoFilter()
    {
        await _navigationService.NavigateAsync(NavigationHelper.ArticlesListPage);
    }
}

XAML:

<StackLayout HorizontalOptions="Center"
         VerticalOptions="Center"
         MinimumWidthRequest="300"
         MinimumHeightRequest="300"
         BackgroundColor="{StaticResource LightBackgroundColor}">
  <StackLayout>
    <StackLayout Orientation="Horizontal">
      <Entry x:Name="priceFromEntry" Placeholder="Price from"/>
      <Entry x:Name="priceToEntry" Placeholder="Price to"/>
    </StackLayout>
    <StackLayout>
      <ListView x:Name="filterListView" ItemsSource="{Binding FilteringOptions.Filters}"
                  IsGroupingEnabled="true"
                  GroupDisplayBinding="{Binding Heading}">
        <ListView.ItemTemplate>
          <DataTemplate>
            <SwitchCell Text="{Binding Text}" On="{Binding Selected}"/>
            <!--<TextCell Text="{Binding Text}"/>-->
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
    </StackLayout>
  </StackLayout>
  <StackLayout Orientation="Horizontal">
    <Button x:Name="filterButton" Text="Filter" Clicked="Filter_Clicked"/>
    <Button x:Name="cancelButton" Text="Cancel" Clicked="Cancel_Clicked"/>
  </StackLayout>
</StackLayout>

Best Answer

Answers

  • kk_kkk_k PLMember

    Thanks!

Sign In or Register to comment.