开发者

How to bind a WPF control value to a method?

开发者 https://www.devze.com 2023-01-09 15:11 出处:网络
Imagine I have a TextBox that it\'s Text should be equal to the number of running processes in the machine.

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开发者_如何学Python or Bindings?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消