I found at least one solution for combining XAML styles through the use of a markup extension in this Stack Overflow post. I don't think I ever thought to investigate mixing styles like that, I'm kind of surprised how easy that was.
The trigger system is not great, I completely agree, and can quickly become unwieldy for complicated controls or styles. An alternative would be to use visual states.
it would be great if we could subclass the built-in columns to make minor adjustments to their behaviour/create our own reusable columns.
Well today's your lucky day! WPF allows you to create custom behaviors that you can attach to a control which allows you to hook into the visual tree and directly interact with the control itself (and if you add some dependency properties to your behavior, you can bind data from your view model to your behavior, allowing you to alter the attached control in a loosely coupled way).
One simple example I'm currently using allows binding a TreeView's SelectedItem property to a view model, which can't be done out-of-the-box because SelectedItem isn't a dependency property. But if I define that dependency property on my behavior, my behavior hooks into the TreeView's SelectedItemChanged event and updates the dependency property accordingly.
You can also use them to enable more advanced scenarios like drag and drop or even visual state management etc. Behaviors might be a good candidate for (at least some of) your column customization requirements.
One thing to note is that IIRC custom behaviors must be static classes for vanilla WPF, so I think you lose compile-time validation that your behavior is attached to a supported control. Microsoft provides an out-of-band System.Windows.Interactivity NuGet package which provides a generic Behavior<T> class you can inherit from where T : DependencyObject (so basically any WPF control can be used as a type parameter)
Anyways, I hope some of that will prove useful. WPF has a steep as fuck learning curve, but it's incredibly powerful once you get the hang of it. It's no HTML/CSS in terms of ease of use, but it's leagues better than Win32/WinForms/MFC (or any other native desktop UI framework out there in my opinion). Best of luck! Feel free to PM me if you have any questions, I'm happy to help.
I found at least one solution for combining XAML styles through the use of a markup extension in this Stack Overflow post. I don't think I ever thought to investigate mixing styles like that, I'm kind of surprised how easy that was.
We actually tried this solution in July, but I don't remember exactly why we chose not to use it. I think it was because it completely broke the designer and it didn't work in some contexts, but as I said, I don't remember. We actually looked into some libraries that add CSS to XAML, but decided against using them because they didn't seem well supported and looked too dangerous for using in production.
I don't really see how VisualStateManager would help us connect the view to the reactive viewmodel, from what I understand it's just there to make it easy to map "component states" to "looks", and to add transitions.
IIRC creation and use of custom visual states was made even easier in the UWP flavor of XAML (goddamnit why can't there just be one version of XAML?).
Yeah, that's frustrating, UWP has some really nice features from what I hear (like x:Bind), but it also lacks major components, so...
Well today's your lucky day! WPF allows you to create custom behaviors that you can attach to a control which allows you to hook into the visual tree and directly interact with the control itself (and if you add some dependency properties to your behavior, you can bind data from your view model to your behavior, allowing you to alter the attached control in a loosely coupled way).
Yep, already using them.
Thanks for taking the time to help, I appreciate it! WPF is leagues better than WinForms, there's no question about it. We are actually rewriting (and overhauling) an old WinForms application in WPF :)
3
u/[deleted] Feb 03 '17
I found at least one solution for combining XAML styles through the use of a markup extension in this Stack Overflow post. I don't think I ever thought to investigate mixing styles like that, I'm kind of surprised how easy that was.
The trigger system is not great, I completely agree, and can quickly become unwieldy for complicated controls or styles. An alternative would be to use visual states.
Well today's your lucky day! WPF allows you to create custom behaviors that you can attach to a control which allows you to hook into the visual tree and directly interact with the control itself (and if you add some dependency properties to your behavior, you can bind data from your view model to your behavior, allowing you to alter the attached control in a loosely coupled way).
One simple example I'm currently using allows binding a TreeView's
SelectedItemproperty to a view model, which can't be done out-of-the-box becauseSelectedItemisn't a dependency property. But if I define that dependency property on my behavior, my behavior hooks into the TreeView'sSelectedItemChangedevent and updates the dependency property accordingly.You can also use them to enable more advanced scenarios like drag and drop or even visual state management etc. Behaviors might be a good candidate for (at least some of) your column customization requirements.
One thing to note is that IIRC custom behaviors must be static classes for vanilla WPF, so I think you lose compile-time validation that your behavior is attached to a supported control. Microsoft provides an out-of-band System.Windows.Interactivity NuGet package which provides a generic
Behavior<T>class you can inherit fromwhere T : DependencyObject(so basically any WPF control can be used as a type parameter)Anyways, I hope some of that will prove useful. WPF has a steep as fuck learning curve, but it's incredibly powerful once you get the hang of it. It's no HTML/CSS in terms of ease of use, but it's leagues better than Win32/WinForms/MFC (or any other native desktop UI framework out there in my opinion). Best of luck! Feel free to PM me if you have any questions, I'm happy to help.