|
-
Mar 30th, 2023, 03:33 PM
#4
Re: WPF Binding Issue
Ah, I see what you're doing.
I was expecting it to handle the binding in a way similar to the odd way that hooking up event handlers works with the Handles clause. You can have some variable declared WithEvents. That variable, being a reference type, holds nothing but a reference to some object, just as my mFoo holds a reference to some object. If you have a bunch of Handles clauses, you can swap the variable around and the event handlers will work fine. I expected similar behavior for WPF binding, since it was bound to a reference type.
I think I'll just abandon the binding for this. It's good to know how I could have done it, but it's three buttons on a complicated form, and the only thing I am doing is coloring the buttons.
Binding is an amazing, powerful, and versatile part of XAML, but it's not always worth it. Those datatriggers can be cool, or they can be overly wordy. This is a case of overly wordy.
EDIT: No, I guess I'll stick with the binding. I thought I only had the three buttons doing any binding on the form, but overlooked two other parts that were also binding and would have had the same issue had I looked close enough. Those two fiddled with visibility rather than color, and one of them I had forgotten I had even added, though now that I see it...it was a good idea.
In fact, much of the form could have been set up using binding, but some of it would have been so terribly painful that it wasn't worth it. I'm still learning where the balance is. I've only been using WPF for a couple months, by now. Everything that can be done via binding can be done without binding as well. I was doing too little with binding when I started, but have gone back and switched some of my early forms around so that they do more with binding. Not everything, though.
I'm not sure what ends up being more readable, in the long run. Datatriggers are pretty nearly self documenting. They can be wordy, but tend to be quite explicit and clear.
Last edited by Shaggy Hiker; Mar 30th, 2023 at 03:47 PM.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|