如何克隆或复制Viewmodel [英] How to clone or copy a Viewmodel
问题描述
我有一个视图模型,它包含其他视图模型。我需要复制或克隆视图模型怎样才能< g class =" gr_ gr_184 gr-alert gr_tiny gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace"数据-GR-ID =" 184"
id =" 184"> i< / g>在WPF中实现它。
场景是
1)我有一个功能区菜单,它包含一些文本字段和下拉列表。我填写文本框中的值并从下拉列表中选择值,该值将根据所选值执行搜索操作,结果将显示在功能区菜单
下方的新选项卡中。
如果我更改了值并执行了新搜索,则应打开一个新标签,并使用新值填充新结果。
当我切换到旧选项卡时,应在功能区菜单中填充旧值,当我导航到新选项卡时,应使用新值填充新结果。
我怎样才能在WPF中实现这一目标?如何在标签之间保持值?
功能区菜单包含所有视图模型,也包括搜索结果。如果你没有得到我可以分享我的代码的问题。
嗨Srinath,
根据你的描述,你有两个问题,一个是如何使用RibbonApplicationMenuItem的命令,另一个是如何克隆viewmodel。 / p>
关于一个问题,您可以查看以下主题:
https://stackoverflow.com/questions/14459336/wpf-ribbon-ribboncommand-replaced-by-icommand
关于另一个问题,有两种方法可以做到这一点,一种是
创建一个通用扩展方法,另一个是实现ICloneable。
https://stackoverflow.com/问题/ 24459399 /如何创建一个数据模型的副本
https://csharp.2000things.com/2010/11/07/143-an-example-of -implementing-icloneable-for-deep-copies /
最诚挚的问候,
I have a view model and it contains other view models. I need to copy or clone the view model how can <g class="gr_ gr_184 gr-alert gr_tiny gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="184" id="184">i</g> achieve it in WPF.
The scenario is
1) I have a ribbon menu, it contains some text fields and dropdowns. I fill the values in the text box and select values from the drop-down which will perform a search operation based on the values selected and the results are displayed in a new tab below the ribbon menu.
If i change the values and perform a new search a new tab should open and new results should be populated with the new values.
When i switch to the old tab old values should populate in the ribbon menu and when i navigate to new tab new results should be populated with the new values.
How can i achieve this in WPF? and how can I maintain the values across tabs?
The ribbon menu contains all the view models include the search results as well. If you didn't get the question I can share my code.
Hi Srinath,
According to your description, you have two questions, one is how to use RibbonApplicationMenuItem's command, another is how to clone viewmodel.
About one question, you can take a look the following thread:
https://stackoverflow.com/questions/14459336/wpf-ribbon-ribboncommand-replaced-by-icommand
About another question, there are two way to do this, one is to create a generic extension method, another is to implementing ICloneable.
https://stackoverflow.com/questions/24459399/how-to-create-a-copy-of-a-data-model
https://csharp.2000things.com/2010/11/07/143-an-example-of-implementing-icloneable-for-deep-copies/
Best Regards,
这篇关于如何克隆或复制Viewmodel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!