Is it possible to do? I am having trouble with finding a way of saving WPF Button's properties using BinaryWriter for a text-based game. The thing is I need it to save button's button1.Content, button1.Click and button1.ToolTip so I can load it back using BinaryReader.
Asked
Active
Viewed 53 times
0
-
There are far too many possible approaches to addressing your specific need. I will note however that generally, you should not be setting control properties directly in the first place, using instead a view model object it is bound to, and so saving is a matter of saving the view model data, not the control data. Please do some research, make an attempt to solve this on your own, and if you still have trouble, post a more specific question in which you've included a good [mcve] that shows clearly what you've tried. – Peter Duniho Jul 03 '16 at 19:07
1 Answers
0
You can save entire Button
, which will be persisted with all its properties.
And you can then de-serialize it back. We can the services provided by using System.Windows.Markup
namespace.
Serialize
Button
with nameBtn
string btnData = XamlWriter.Save(Btn);
Deserialize it back
Button btn = (Button) XamlReader.Parse(btnData);

AnjumSKhan
- 9,647
- 1
- 26
- 38