Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

SortDescriptions wpf

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;

namespace SortDemo
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            Items = new ObservableCollection<Item>();
            Items.Add(new Item() { ID = "AAA", Value = 2 });
            Items.Add(new Item() { ID = "BBB", Value = 1 });

            DataContext = this;
        }

        public ObservableCollection<Item> Items { get; private set; }

        private void OnSort(object sender, RoutedEventArgs e)
        {
            string sortProperty = (sender as FrameworkElement).Tag as string;
            _itemsControl.Items.SortDescriptions.Clear();
            _itemsControl.Items.SortDescriptions.Add(new SortDescription(sortProperty, ListSortDirection.Ascending)); 
        }
    }

    public class Item
    {
        public string ID { get; set;}
        public int Value { get; set; }

        public override string ToString()
        {
            return ID + " " + Value;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to system func bool unity 
Csharp :: // Force WPF to render UI changes immediately with this magic line of code... 
Csharp :: mongodb truncation exception c# 
Csharp :: how to extract data from a document using c# 
Csharp :: c# datafield change cell background color 
Csharp :: c# simplified if statement 
Csharp :: how to change font text mesh pro 
Csharp :: prevent C# app from lingering after closing in background processes 
Csharp :: c# aabb box rotate 
Csharp :: add dynamic value in startup file in .net core api 
Csharp :: List foreach 
Csharp :: set-variables-from-an-object-using-reflection 
Csharp :: c# remove duplicate cards 
Csharp :: Get cell value with formatting openxml 
Csharp :: how to configure asp.net core on ionon 1&1 hosting 
Csharp :: Open API support for ASP.NET Core Minimal API 
Csharp :: c# function<T 
Csharp :: f sharp make parameter mutable 
Csharp :: c# read csv file save to database dynamically 
Csharp :: WPF combobox filter as you type 
Csharp :: taskcontinuationoptions.onlyonfaulted 
Csharp :: add css class based on model value razor 
Csharp :: get path revit link unloaded 
Csharp :: Maximize Print Preview 
Csharp :: C# system dont let write txt file 
Csharp :: how to unfocus a richtextbox windows forms 
Csharp :: How to keep line breaks in SQL Server using ASP.NET and C#? 
Csharp :: add new page itext 7 
Csharp :: basic math functions in c# 
Csharp :: show in editor unity 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =