I’m looking for a good way to Bind a property of a control to an existing object property for automatic updating Without polling. The instance of the object and the instance of the control will be created AND associated at runtime. The object doesn’t have a property changed event. Anyone have any creative suggestions, please don’t say poll with a timer, that’s such a cludge.
I hate to sound ignorant, but that's essentially what I'm asking, how exactly would I go about creating a change event for something that has no method of triggering said event.
Are you talking about trapping messages for the control and creating an event routine to execute based on the receipt of a specific message?
Just as an example, say I wanted to update my control property when the user changes the picture in an image control. There is no event associated with a Picture Change. This is just a hypothetical example, as in my actual application there are potentially a dozen or more different custom controls whose properties need to be set based on the value of their associated variables and the variable types differ from control/variable pair to control/variable pair. The values are constantly changing on the variables and the controls need to reflect the change visually in real-time. If I had a change event for the variable it would be a snap because I could do a property set every time the variable changed.
External Process updates Variable(Object Property)
Visual indicator (custom control) reflects a visual change based on a State Property.
The external process can't communicate directly to the Control so the Control must read the Variable that the External Process is writing to in order to reflect a state change.
Ah yes, I know what a wrapper class is. In fact most of the custom controls in question, the ones that need the value bound are essentially wrapper controls. I had thought of doing that, but since the property I need to Bind to the control is a property of a an OPC Class object I'm not too sure about wrapping those classes. I've finally got all my OPC bugs ironed out and got good communication with my server, I hate to start tinkering with with them, I'm just not that good of a programmer. Worst case scenarlo I will use a timer based polling method on a form by form basis. But I'm wondering about trapping messages and routing through a custom event routine. What do you think?
For the benefit of anyone following the thread, I'm posting an example project with a quick down an dirty wrapper class for an image control. The class provides a PictureChange event that I've used to set the picture property of an image control with. I also set the Image.Tag = to the Image filename.
In this example you store the stdPicture object (long pointer) and the complete path and filename for the image in the properties of the class object, then rather than directly updating the image properties (picture, stretct, tag etc.) you set these for the Class object then use the change event to transfer the properties to the image control.
It might help to know what sort of external process you're talking about. The more detail you can provide, the better the chances of getting useful suggestions.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
WizBang in my previous post I mentioned that the variable was a property of an instance of an OPC class object. The external process is an OPC server providing real time values from an Industrial Programmable Logic Controller that is controlling a machine process. Although OPC is a bit finicky, I was actually able to modify the OPCItem Class and create a DataChanged Event. Now I just declare my Class Object WithEvents and I'm getting an event from the data change without having to poll.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.