在窗口内的多个用户控件上保存/加载用户设置
这篇文章与 c# - 保存用户设置的方法相关在 WPF 应用程序中?
我找到了多个保存/加载一个窗口配置的示例,但我不确定它是否还会保存该窗口内打开的所有用户控件的配置或仅保存实际的主窗口配置...
首先是否有可能使用应用程序/用户设置在窗口内保存/加载多个用户控件配置?
我是否被迫只读取/写入 xml 来存储多个用户控件配置?
预先感谢,如果您需要任何其他信息,请告诉我!
编辑
我有一个顶部带有功能区栏的应用程序,允许用户从功能区栏打开一个或多个用户控件。假设如果我想保存所有打开的用户控件窗口位置、高度、宽度等...是否仍然可以使用应用程序设置来完成此操作?
EDIT2
我有一个应用程序,在该应用程序中,有许多用户可以访问的用户控件。如果用户打开 2 个用户控件并经常使用这些控件,我希望能够将这些用户控件保存到工作区,以便在程序打开或关闭时始终存在。我现在处理它的方法是使用数据库中的序列化 xml。我正在研究这个主题,并遇到了应用程序设置方法,并想知道这是否适合我的情况。再次感谢马克花时间帮助我解决这个问题。
This post is related to c# - approach for saving user settings in a WPF application?
I have found multiple examples for saving/loading one window configuration but I am not sure if it will also save the configurations for all usercontrols open inside that window or just the actual main windows configuration...
First is it possible to save/load multiple usercontrol configurations inside a window using the application/user settings?
Am I forced to just read/write xml to store the the multiple usercontrols configuration?
Thanks in advance and let me know if you need any other information!
EDIT
I have an application with a ribbonbar on top that allows the user to open one or more user controls from the ribbonbar. Hypothetically if i wanted to save all the open usercontrols window position, height, width, etc... would it still be possible to use the application settings to accomplish this?
EDIT2
I have an application and within that application there are many usercontrols a user can access. If a user opens 2 usercontrols and uses those controls often, I want to be able to save those usercontrols to the workspace so there always there when the program is open or closed. The way I am approaching it now is with serialized xml from the database. I was researching this topic and came across the application settings approach and wanted to know if this was a viable approach for my situation. Thanks again Marc for taking the time to help me figure this problem out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用的是用户特定的 ApplicationSettings 并将它们绑定到我想要“保存”的属性。这是我所做的一个很好的例子 http ://www.jaylee.org/post/2007/02/WPF-DataBinding-and-Application-Settings.aspx
What I've used is user-specific ApplicationSettings and binding those to properties I want to 'save'. Here's a good example of what I've done http://www.jaylee.org/post/2007/02/WPF-DataBinding-and-Application-Settings.aspx
我更多的细节可能会有所帮助,我不确定我是否遵循。您是说单个窗口上有给定用户控件的多个实例,并且您希望保留每个实例的属性吗?
这很大程度上取决于您如何创建和填充这些控件。例如,如果它们是根据数据动态创建的,则最佳解决方案是将数据序列化到磁盘并在应用程序重新启动时重新创建控件。
或者,您可以将设置的序列化烘焙到用户控件本身中,以便它根据其实例名称(control1.xml、control2.xml 等)将其设置写入文件名,然后在实例时重新填充它复活了。
首先了解如何添加这些控件以及如何设置属性会很有帮助。
I little more detail might be helpful here, I'm not sure I follow. Are you saying you have multiple instances of a given user control on a single window and you want to persist the properties for each of them?
A lot of this depends on how you created and populated those controls. If they were created dynamically from data for example, the best solution is to serialize that data to disk and re-create the controls when the application restarts.
Alternatively you could bake in the serialization of the settings into the user control itself such that it writes out it's settings to a file name based on it's instance name (control1.xml, control2.xml, etc) and then have it repopulate when the instance comes back to life.
Knowing how these controls are added and the properties are set in first place would be helpful.