简体   繁体   English

在切换到其他控件之前,如何在用户控件上保存数据?

[英]How do I save the data on a user control before switching to a different one?

I have a WPF Application with different user controls. 我有一个具有不同用户控件的WPF应用程序。 Each of them can be accessed by clicking a button on the left side. 单击左侧的按钮可以访问它们中的每一个。 My issue is, when I am in one of the user controls and filling out the data in textboxes, combo boxes etc, I may have to stop it mid way and click on another user control. 我的问题是,当我进入一个用户控件并在文本框,组合框等中填写数据时,我可能必须在途中将其停止并单击另一个用户控件。 While doing that, I need to keep the data in the previous user control intact so that when I return to the first user control, the data should be present in all the controls before I left it. 在执行此操作时,我需要保持先前用户控件中的数据完整无缺,以便当我返回第一个用户控件时,在离开它之前,数据应该存在于所有控件中。 How do I achieve this? 我该如何实现? Here's a sample picture of how my application looks like: 这是我的应用程序外观的示例图片:

在此处输入图片说明

Picture Credit: https://rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/ 图片来源: https : //rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/

From the picture, if I am in the Products Page, I might have several text boxes with data entered in there. 从图片中,如果我在“产品”页面中,则可能会有几个文本框,其中输入了数据。 For a variety of reasons, I may have to step away from this and click on Home Page or some other page , do some work there and return back to the Products page. 由于种种原因,我可能不得不离开此页面,然后单击“主页”或其他页面,在那里做一些工作,然后返回“产品”页面。 When I return, I need the data to be present as is when I left it. 当我返回时,我需要在离开时按原样显示数据。

Thanks in Advance 提前致谢

You must have create a ViewModel to each diferent user control. 您必须为每个不同的用户控件创建一个ViewModel。 ViewModel remains in memory until you process that or make a diferent process. ViewModel保留在内存中,直到您进行处理或进行其他处理为止。 For Example you hava a User control for your Main Page, that's mean you have a view (MainPageView) of your user control for your main page, that view belong to a ViewModelMainPage. 例如,您为主页拥有一个User控件,这意味着您拥有主页的用户控件的视图(MainPageView),该视图属于ViewModelMainPage。 For Products you maybe have a ProductView, that's belong to ViewModelProducts. 对于产品,您可能有一个ProductView,它属于ViewModelProducts。 You must create a ManagerViewModel to manage the view for diferents user control. 您必须创建一个ManagerViewModel来管理不同用户控件的视图。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从一个视图切换到另一个视图时,如何保持用户控件的 Textbox Text 属性的值? - How do I persist the value of the Textbox Text property of a user control when switching from one view to another? WPF:如何将一个用户控件用于多个不同的Click事件 - WPF: How do I use one User control for multiple different Click events 如何创建具有3个组合框和每个组合框具有不同数据绑定的用户控件? - How do I create a user control with 3 combo boxes and a different data binding for each? 如何在两个不同的模块中使用相同的用户控件 - How do i use the same user control in two different modules 如何从一个用户控件导航到另一个 - How do I navigate from one user control to another 如何设置绑定,以便一个控件中组合框的选定值更改另一控件的控件模板? - How do I setup binding so that selected value of combobox in one control changes control template of a different control? 如何将带有数据的用户控件转换并保存到图像中? - How to convert and save User Control with data in to image? 如何将数据从一个用户控件发送到另一个用户控件? - How to send data from one User Control to another User Control? 如何将XML保存在Web浏览器控件中? - How do I save xml in a webbrowser control? 如何从代码隐藏中在用户控件的内容控件中的数据模板中启动故事板? - How do I start a Storyboard in a Data Template in a Content Control in a User Control from codebehind?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM