开发者

save textbox or check values C# WPF .Net VS2008

开发者 https://www.devze.com 2023-03-14 18:14 出处:网络
i have m开发者_运维问答any textbox and check box on my wpf . how to save entered values as a separate (any format) file , so that values can be loaded when ever required.

i have m开发者_运维问答any textbox and check box on my wpf . how to save entered values as a separate (any format) file , so that values can be loaded when ever required.

thanks


You can create a class with relevant properties in which you store the values, then your elements can be bound to those properties and the file can be serialized and deserialized as XML for example.


I assume you want a method to avoid assigning an x:Name to each TextBox or CheckBox and writing a line of code for each. My suggestion is to assign a Tag string that begins with some constant, such as "$SaveMe$". Then either concatenate a unique name or assign an x:Name to each. Your code can then do a single recursion, walking the visual tree and grabbing each TextBox or CheckBox with the indicated tag value and writing it with an XmlWriter. Similarly you can load it back with an XmlReader when the x:Name or remaining Tag value matches the Xml name.

0

精彩评论

暂无评论...
验证码 换一张
取 消