[英]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.