Могу ли я отсортировать ListView или ListView.ItemTemplate по значению, указанному c? - PullRequest
0 голосов
/ 30 марта 2020

Я пытаюсь отсортировать или упорядочить ListView по значению в указанном c, например по дате, но у меня ничего подобного нет, я хочу отсортировать значения из API, например по дате, но там Уведомления типа Важно и Не важно, я сделал это в Грид-сети

photo

Я должен сделать то же самое, но в ListView в Xamarin

Мой ListView:

<ListView  x:Name="ItemsListView" RefreshCommand="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=OneWay}" SeparatorVisibility="None" Style="{ StaticResource ResponsiveLandscapeMarginStyle }" ItemsSource="{ Binding Messages }">
    <ListView.RowHeight>
        <OnIdiom x:TypeArguments="x:Int32" Phone="120" Tablet="160" />
    </ListView.RowHeight>

<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>

            <local:DataItemTemplate />

        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>

Моя ViewModel:

    public ObservableCollection<Notice> Messages { get; set; }
    public Command LoadItemsCommand { get; set; }
    public Command LoadHighImportantItems { get; set; }

    public Notice Message { get; set; }
    public Command UpdateMessage { get; }
    /// <summary>
    /// Metodo constructor para inicializar propiedades
    /// </summary>
    public NoticeViewModel()
    {
        Messages = new ObservableCollection<Notice>();
        LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
        LoadHighImportantItems = new Command(() => ExecuteLoadHighImportantItemsCommand());
        UpdateMessage = new Command(() => ExecuteUpdateRead());
    }

    /// <summary>
    /// Metodo para cargar todos los avisos
    /// </summary>
    /// <returns></returns>
    async Task ExecuteLoadItemsCommand()
    {

        if (IsBusy)
            return;
        IsBusy = true;

        try
        {
            var serviceStore = new ServiceStoreAPI();
            await serviceStore.GetItemsAsync(ServicesKey.Event,true);
            await serviceStore.GetItemsAsync(ServicesKey.EmployeeServicesRequests, true);
            await serviceStore.GetItemsAsync(ServicesKey.Raffle, true);
            new EmployeeServicesRequestsViewModel().LoadItemsCommand.Execute(null);
            new RaffleViewModel().LoadItemsCommand.Execute(null);
            Messages.Clear();
            var items = await NoticeStore.GetItemsAsync(true);

            foreach (var item in items)
                Messages.Add(item);
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        finally
        {
            IsBusy = false;
        }
    }

Есть ли способ сортировки по дате или по любому значению, отобразить значения в ListView?

Ответы [ 2 ]

0 голосов
/ 07 мая 2020

Я хотел бы использовать CollectionViewSource для вывода заказа:

<CollectionViewSource x:Key="SortedComboBoxItems" Source="{Binding Path=ComboBoxItems}">
    <CollectionViewSource.SortDescriptions>
        <componentModel:SortDescription PropertyName="Order" />
    </CollectionViewSource.SortDescriptions>
</CollectionViewSource>
0 голосов
/ 30 марта 2020

Я пробовал это

foreach (var item in items.OrderByDescending(d => d.Date)
  Messages.Add(item);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...