Modifié (je ne compte pour lui vouloir mise à jour automatique):
Voilà a link d'une classe « Ticker » qui utilise INotifyPropertyChanged pour qu'il se mette à jour automatiquement. Voici le code du site:
namespace TheJoyOfCode.WpfExample
{
public class Ticker : INotifyPropertyChanged
{
public Ticker()
{
Timer timer = new Timer();
timer.Interval = 1000; // 1 second updates
timer.Elapsed += timer_Elapsed;
timer.Start();
}
public DateTime Now
{
get { return DateTime.Now; }
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Now"));
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
<Page.Resources>
<src:Ticker x:Key="ticker" />
</Page.Resources>
<TextBox Text="{Binding Source={StaticResource ticker}, Path=Now, Mode=OneWay}"/>
Declare:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Maintenant, cela fonctionnera:
<TextBox Text="{Binding Source={StaticResource ticker}, Path=Now, Mode=OneWay}"/>
Mauvais. Cela n'aidera pas. (C'est exactement ce qu'il a écrit) – SLaks
Et pourquoi ça ne marchera pas? –
Parce qu'il ne sera toujours pas mis à jour. Lisez la question à nouveau. – SLaks