Making a Custom Binding Extension
Recently, I was reading an article on Josh Smith’s blog about how to set the focus from inside the View Model of a MVVM pattern using a custom MarkupExtension class. While this article was very interesting in and of itself (and I’ll definitely be employing this approach as I continue in my own MVVM adventures), the part that really caught my interest was the link to Philipp Sumi’s blog about how to write a custom a Binding extension class.
This was especially interesting to me because a couple of weeks ago, while working on a custom WPF Theme (see a future post about that), I tried to extend the DynamicResourceExtension class and encountered the same sort of problem that Philipp Sumi encountered – that the necessary parts of DynamicResourceExtension were either sealed or internal.
Philipp’s solution was to extend MarkupExtension rather than Binding or BindingBase, and to internally create a Binding. I believe that this approach can be used to wrap a DynamicResource markup in the same way. I’ll delve into this in greater detail when I blog about authoring a WPF Theme in the next few weeks.