I have a WPF application that encapsulates the editing of a dozen or so xml config files in a single place so that a deployment engineer does not have to know where things may or may not be changed. At the moment each config is represented as its own object with the logic to update various UI items as standard get and set functions.
One other feature is that the application should read in an older version of these config files and copy any changed values to a new installation. Really easy since we’re using object representations of each file.
I’ve been looking at WPF databinding and while it looks great for reading and writing XML and displaying on the various application controls, I’m having trouble figuring out just how I would implement the copying part. Would I be heading down a wrong path by using Databinding at all?
The answer to the question, “Should I use data binding in WPF?” is almost invariably “Yes.” The real question is more along the lines, “What should I use WPF data binding for?”
It sounds as though the architecture of your application is currently:
In WPF, you’ll want to use data binding to connect the object model to the UI controls. All of the functionality in your current object model that copies XML files around and updates their contents and so on, all of that happens in another universe, as far as WPF is concerned.
If the methods currently implemented in your object model make changes to the objects’ properties that need to be pushed out to the UI, things may get a little more complicated. For instance, you may find that you want to create
Commandobjects to expose these methods to the UI, and then need to implement some mechanism for raisingPropertyChangedevents after the methods change the objects’ properties. Depending on the overall architecture of your application, you may not want to integrate WPF objects (e.g. commands) or implement property-change notification in your object model.That gets you into the territory of the MVVM pattern (the “viewmodel layer” that Joe White alludes to), which is a way of encapsulating commands and property-change notification (and other stuff that a WPF UI needs) without having to modify the underlying object model. That’s OK. It’s a little overwhelming the first time you do it, mostly because the information you’ll find when you start researching it will show you solutions to problems that you may not have (or may not have yet). But really it’s not so bad.