intee_
✅ Deserialize JSON back into custom object
Hey all,
I have an ObservableCollection that I am using to store a list of tasks (A custom object "TaskItem" that is build like this.
And in my ViewModel I'm creating an ObservableCollection of those item types, called "TaskList".
I am exporting that list of TaskItems to Json and that works fine with the below:
But I can't seem to work out how the hell I load that back into TaskList variable when I re-open the app.
I have been messing around with this in the ViewModel constructor:
Trieda bunch of different stuff in there, this was just what I gave up on haha.
Am I at least getting close? haha.
6 replies
✅ How does the button know what to do?
Hey, new to C# and wrapping my head around following MVVM. Can someone help me understand how the button knows what to do here? When adding a new button or data binding, they all trigger each other (if that makes sense...). Will any button trigger all data bindings unless otherwise set with like a command relay or something?
XAML:
Code Behind:
View Model:
39 replies
✅ Invoking an event on property changed (WPF)
Hey all, Just wondering if someone can help me wrap my head around how this works, I am not sure where I am getting caught up but I am sure I am not understanding something. Just started learning WPF and C#. Sorry for the data dump.
I have a text box, a button and a textblock. I am just trying to make the text from the text box be set in the textblock. I have have my bindings working but I don't understand HOW they are working.
I have a
PropertyChangedEventHandler
in my main window code behind and I have the public and private properties for the binding as well. In the setter of the binding I am calling PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("DisplayText"));
This is where I am getting confused I think. When a property is changed on the UI the properties setter is called by that event handler (Handled by INotifyPropertyChanged) (???) How exactly does this part of it work?
I'm not using any relay commands or anything like that, just straight data binding from the UI to the code behind.
Hope this makes at least a little sense...11 replies