WPF C# Tutorial

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:c="clr-namespace:WpfApplication1" Width="300" Height="300"
  Name="Page1">
  
    
    
    
      
      
    
  

  
  
    
  

  
  
  
  
    
      
    

  

//File:Window.xaml.cs
using System;
using System.Globalization;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Data;
using System.Windows.Media;
namespace WpfApplication1
{
  public class MyConverter : IValueConverter
  {
    public object Convert(object o, Type type,object parameter, CultureInfo culture){
        DateTime date = (DateTime)o;
        switch (type.Name)
        {
            case "String":
                return date.ToString("F", culture);
            case "Brush":
                return Brushes.Red;
            default:
                return o;
      }
    }
    public object ConvertBack(object o, Type type,object parameter, CultureInfo culture){
          return null;
    }
  }
  public class MyData: INotifyPropertyChanged{
    private DateTime thedate;
    public MyData(){
      thedate = DateTime.Now;
    }
    public DateTime TheDate
    {
      get{return thedate;}
      set{
        thedate = value;
        OnPropertyChanged("TheDate");
      }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged(String info)
    {
      if (PropertyChanged !=null)
      {
        PropertyChanged(this, new PropertyChangedEventArgs(info));
      }
    }
  }
}