Clint
Saving Draggable objects location wpf
You could also make it not use
object
and use JsonElement
for example, but then System.Text.JSON
contains primitives for making this slightly more workable like the JSON writer / reader utilities etc.
Lots of ways to potentially solve this.
Another of course would be to make your viewmodels derive from a persistable base, something like:
And then implementing it would be something like:
Then you have a well-defined data model for your persistance, that you can then ser/deser however you want, and is easy enough to just treat wholesale for your JSON storage.
Your viewmodels can then be as complex as needed, and all you're worried about is upholding that in/out data contract, and the persistance code can take care of the rest.18 replies
Saving Draggable objects location wpf
Hmmmm, my recommendation would be instead to implement an interface something like
Then have your items implement it, this is sort of similar to how certain things in Apple's ecosystem work, so the idea being your individual types can pack and unpack their specific pieces of data, and you have a consistent interface to interact with that mechanism without having to resort to reflection. Also means you're not necessarily tied into JSON going forward either.
18 replies
Saving Draggable objects location wpf
So let's say you have these items that users can drag around on a canvas, your ViewModels for each item will be unique to their own usecases, but they all share something in common, that is the fact they belong on the canvas and store positional data, so you could have your base view model type:
Omitted the
INotifyPropertyChanged
stuff for brevity.
Then let's say you have a VM to represent your canvas container itself:
If you have additional serialisation / deserialisation needs per-item, e.g. having them store and load additional data relevant to them, then you'd want to come up with a more comprehensive mechanism for storing their own data, but this would be how I'd start to tackle the problem.18 replies
How to find and update a record in a recursive model?
What is it you're actually trying to do here? The code isn't super clear about what the problem you're facing is.
My recommendation would be to rely on
XDocument
as you get all the tree traversal built-in via Descendants
.16 replies
Saving Draggable objects location wpf
I'd recommend setting up a base view model type that these items' view models can derive from, placing their positioning properties on that base type, and that way you don't have to worry about putting them on every class.
You can then pretty easily have your collection where all those items are stored in a VM just be a collection of that base type, and implement your persist / reload logic at that level.
18 replies