wpf - Binding to DateTime.Now. Update the value -
OK, I had to pair the date time.Now for a text block, I used it:
< Pre> text = "{binding source = {x}: static system: datetime.now}, stringformat = 'hh: mm: ss tt'}"
Force to update? This is the time when the control is loaded and it is not updated ...
Edit (I didn't want to update it automatically):
There is a 'ticker' class which uses INotifyPropertyChanged, so it will automatically update the code from the site here Gone:
Namespace theJoyOfCode.WpfExample {Public class ticker: INotifyPropertyChanged {public ticker} {timer timer = new timer (); Timer Interval = 1000; // 1 second update timer. Elapsed + = timer_Elapsed; Timer.start (); } Public Date Time Now {Get Date Date Now; }} Void timer_Elapsed (Object Sender, ElapsedEventArgs E) {If (PropertyChanged! = Null) property changed (this, new PropertyChangedEventArgs ("now")); } Private Event PropertyChangedEventHandler PropertyChanged; }} & Lt; Page.Resources & gt; & Lt; Src: ticker x: key = "ticker" /> & Lt; /Page.Resources> & Lt; Text box text = "{binding source = {static resource ticker}, path = now, mode = wrench}" />
Announce:xmlns: sys = "clr-namespace: system; assembly = mscorlib" < / Code>
This will now work:
& lt; Text box text = "{binding source = {static resource ticker}, path = now, mode = oneway}" />
Comments
Post a Comment