views:

103

answers:

3

I've seen in WPF where you can bind control values to properties of other controls. How is that binding accomplished in C++?

For example, if I have a class called Car and a guage control called RPM, how do I tie the value of RPM to the member variable Car.RPM, so that when Car.RPM changes, it is automatically (as in without a specific update call coded by me) reflected by the RPM control?

General answers or directions to pertinent resources would be fine also, as I'm just beginning to dabble in C++ and haven't had much Google luck with this particular question.

EDIT: See comments for further clarification.

+1  A: 

You mention WPF in your question, but is that an example of the type of binding that you want to do, or are you writing a WPF application in C++? (If it's the latter, why?)

In any case, most WPF binding is designed to be done in Xaml, not in the code. While it's possible to do, great pains were taken in rewriting the WPF/Xaml data binding system based upon the shorcomings in the binding found in Winforms, so make use of it.

Adam Robinson
+1  A: 

It sounds like you want to have a pointer to the value Car.RPM in the gauge control. But the control will never be updated like you want to.

In pure C++ this sounds like work for the Observer-Observable pattern, or a simple callback function.

daramarak
Thank you! This sounds like it may be just what I'm looking for.
Rich.Carpenter
A: 

You cannot write WPF applications in C++. Are you sure you don't mean C++/CLI?

If that is the case, just take a look at any examples for C# - they are trivially convertible to C++/CLI.

BlueRaja - Danny Pflughoeft