xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:MyNameSpace.FormattedDigitalClock"
Title="Formatted Digital Clock">
Converter="{StaticResource conv}"
ConverterParameter="... {0:T} ..." />
//File:Window.xaml.cs
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;
using System.Globalization;
using System.Windows.Data;
namespace MyNameSpace.FormattedDigitalClock
{
public class ClockTicker : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public DateTime DateTime
{
get { return DateTime.Now; }
}
public ClockTicker()
{
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += TimerOnTick;
timer.Interval = TimeSpan.FromSeconds(1);
timer.Start();
}
void TimerOnTick(object sender, EventArgs args)
{
if (PropertyChanged != null)
PropertyChanged(this,new PropertyChangedEventArgs("DateTime"));
}
}
public class FormattedTextConverter : IValueConverter{
public object Convert(object value, Type typeTarget,object param, CultureInfo culture)
{
if (param is string)
return String.Format(param as string, value);
return value.ToString();
}
public object ConvertBack(object value, Type typeTarget,object param, CultureInfo culture)
{
return null;
}
}
}