views:

40

answers:

1

Imagine I have a TextBox that it's Text should be equal to the number of running processes in the machine.

How to make it to update without using timers? Is there a way using Dependency Property or Bindings?

+4  A: 

I'm not sure what this has to with binding to a method.

You'd have to keep calling the method on a timer, just the same.

You can set the DataContext to an object that implements INotifyPropertyChanged and exposes a property with the data you want (the getter can, of course, call a method).

Without a timer, you'll need an event to which your data object can subscribe, and then you can raise a notification that the property of interest has changed each time the event fires, and the UI element bound to that property will be updated.

Jay
I thought that a WPF would check its value every renderization, which is periodic, so I wouldn't have to use a timer since the method would be called periodically anyway.
Jader Dias
No, it does not re-fetch data unless it is explicitly told to do so with `.BindingExpression(…).UpdateTarget()` or notified of a change (usually through `INotifyPropertyChanged`).
Jay