WPF C# Tutorial

    x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1"
    Title="WPF" Height="300" Width="180">
    
        
    

    
        
            
            
        

    


//File:Window.xaml.cs
using System;
using System.Collections;
using System.Windows;
using System.Windows.Data;
using System.Collections.ObjectModel;
namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void SortButton_Click(object sender, RoutedEventArgs args)
        {
            SortableCountries sortableCountries = (SortableCountries)(this.Resources["sortableCountries"]);
            ListCollectionView lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(sortableCountries);
            lcv.CustomSort = new SortCountries();
        }
    }
    public class SortCountries : IComparer
    {
        public int Compare(object x, object y)
        {
            string stringX = x.ToString();
            string stringY = y.ToString();
            
            return stringX.CompareTo(stringY);
        }
    }
    public class SortableCountries : ObservableCollection
    {
        public SortableCountries()
        {
            this.Add("C");
            this.Add("B");
            this.Add("A");
        }
    }
}