Prism / MEF新视图没有从MEF导入获取新的视图模型(Prism / MEF new view not getting a new viewmodel from MEF import)
我有一个标签式应用程序,我希望用户能够搜索一个人,然后在新视图中显示该人的详细信息。 用户应该能够为不同的人打开多个人员详细信息视图。
我有点不确定我是否遵循了创建新视图的正确程序。 使用Unity(我不是),似乎你会调用
Container.Resolve(view)
但是我正在执行以下操作,为了在view / viewmodel中创建导入,satisfImports是必需的。PersonDetailView view = new PersonDetailView(); _container.SatisfyImportsOnce(view); _regionManager.Regions["MainRegion"].Add(view, this.SelectedPerson.Name); _regionManager.RequestNavigate("MainRegion", new Uri("PersonDetailView", UriKind.Relative));
在我的PersonDetailView的代码中,我有以下属性来设置数据上下文。
[Import] public PersonDetailsViewModel ViewModel { set { this.DataContext = value; } }
这似乎有效,但我遇到的麻烦是,当我创建第二人称视图时,新视图获取与已创建的视图相同的datacontext实例。
这是因为我正在错误地创建我的观点,还是有一种方法可以告诉MEF在满足我的新视图的导入时创建新的对象?
I have a tabbed application where I want the user to be able to search for a person and then, in a new view, show the person's details. The user should be able to have multiple person detail views open for different people.
I was a little unsure if I am following the correct procedure for creating my new view. Using Unity (which I am not) it seems you would call
Container.Resolve(view)
however I am doing the following, the satisfyImports was necessary in order for my imports in the view / viewmodel to be created.PersonDetailView view = new PersonDetailView(); _container.SatisfyImportsOnce(view); _regionManager.Regions["MainRegion"].Add(view, this.SelectedPerson.Name); _regionManager.RequestNavigate("MainRegion", new Uri("PersonDetailView", UriKind.Relative));
In the code for my PersonDetailView I have the following property to set the data context.
[Import] public PersonDetailsViewModel ViewModel { set { this.DataContext = value; } }
This seems to work but the trouble I am having is that when I create a second person view, the new view is getting the same instance of the datacontext as the view that is already created.
Is this because I am creating my views incorrectly or is there a way that I tell MEF to create a new oject when it fulfills the imports for my new view?
原文:https://stackoverflow.com/questions/5484880
最满意答案
以下是我在项目中的工作,
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-director-plugin</artifactId> <version>${tycho-version}</version> <executions> <execution> <id>materialize-products</id> <goals> <goal>materialize-products</goal> </goals> <configuration> <installFeatures>false</installFeatures> <profile>Installer</profile> </configuration> </execution> <execution> <id>archive-products</id> <goals> <goal>archive-products</goal> </goals> </execution> </executions> </plugin> <!-- ANT actions --> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <!-- Rename the ZIP files --> <execution> <id>update-zip-files</id> <phase>install</phase> <configuration> <target> <!-- Rename the products --> <move verbose="true" todir="${project.build.directory}/products"> <mapper type="regexp" from="^(Installer-)(.*)$$" to="\1N-${maven.build.timestamp}-\2" /> <fileset dir="${project.build.directory}/products"> <include name="*.zip" /> </fileset> </move> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
Below is what I do in my project,
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-director-plugin</artifactId> <version>${tycho-version}</version> <executions> <execution> <id>materialize-products</id> <goals> <goal>materialize-products</goal> </goals> <configuration> <installFeatures>false</installFeatures> <profile>Installer</profile> </configuration> </execution> <execution> <id>archive-products</id> <goals> <goal>archive-products</goal> </goals> </execution> </executions> </plugin> <!-- ANT actions --> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <!-- Rename the ZIP files --> <execution> <id>update-zip-files</id> <phase>install</phase> <configuration> <target> <!-- Rename the products --> <move verbose="true" todir="${project.build.directory}/products"> <mapper type="regexp" from="^(Installer-)(.*)$$" to="\1N-${maven.build.timestamp}-\2" /> <fileset dir="${project.build.directory}/products"> <include name="*.zip" /> </fileset> </move> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
相关问答
更多-
在eclipse-repository的默认生命周期[1]中有一个maven clean插件,但它默认映射到生命周期阶段'initialize'。 在构建日志中使用id“default-clean-1”进行的干净调用对我来说很奇怪。 这可能是由分叉的maven生命周期引起的。 maven-source-plugin可能对此负责(至少我不希望在构建eclipse-repository包装类型时执行maven-source-plugin) 看起来[2]是相关的。 尝试删除maven-source-plugin或 ...
-
批量 - 提取许多zip,重命名在同一目录中提取的文件(Batch - Extract many zip, rename files extracted in a same directory)[2022-04-28]
在不知道存档内容的情况下,您无法知道要重命名的文件,因为您将它们放入可能已包含其他文件的目录中。 但是,如果有一个临时放置文件的专用目录,这将更容易。 以下是您可以使用它的方法: @ECHO OFF SET "srcdir=G:\toto" SET "tgtdir=G:\toto\extracted" SET "tmpdir=G:\toto\extracted-tmp" FOR %%Z IN ("%srcdir%\*.zip") DO ( unpack "%%Z" with your favourite ... -
这是由于RecursiveDirectoryIterator(即../uploads/)中的路径,一旦我将代码移动到主文件夹并将路径更改为(上传/)所有开始正常工作的路径。 荣誉! It was due to path in RecursiveDirectoryIterator (i.e ../uploads/) once i moved the code to main folder and changed the path to (uploads/) everything started working ...
-
是的,可以使用像adm-zip这样的库 var AdmZip = require('adm-zip'); //create a zip object to hold the new zip files var newZip = new AdmZip(); // reading archives var zip = new AdmZip('somePath/download.zip'); var zipEntries = zip.getEntries(); // an array of ZipEntry ...
-
使用gradle在已创建的zip文件中包含其他文件(Include additional files in an already created zip file using gradle)[2023-02-02]
我使用分发插件工作了。 我在自定义插件项目中添加了插件,在我的项目中,我添加了要添加到我的zip文件夹的文件集,如下所示: distributions{ myZip{ from('path'){ include 'file' } } } I got this working using distribution plugin. I added the ... -
重命名由tycho-p2-director-plugin创建的ZIP文件(rename ZIP files created by tycho-p2-director-plugin)[2024-02-26]
以下是我在项目中的工作,org.eclipse.tycho tycho-p2-director-plugin ${tycho-version} ... -
没有理由需要在压缩文件中订购文件,您可以获取文件列表并按照您喜欢的顺序给它: using (ZipFile zip = ZipFile.Read(NameOfExistingZipFile)) { foreach (ZipEntry e in zip.Order(x => x.FileName)) { // do your styff e.Extract(); } } There is not reason the files have to be orde ...
-
尝试这个 md textfiles for %%f in (*.7z) do ( 7z e "%%f" move *.txt textfiles\%%~nf.txt ) xcopy textfiles\*.txt originalfolder rd textfiles /s /q 只需确保此文件夹中没有现有的文本文件即可。 它只是创建一个临时文件夹并将所有文本文件移动到那里(当时只有提取的文件文件存在,但这不知道文件名),并将其重命名为zip文件名。 完成所有提取和重命名后,只需将所有文本文件移回原始文件 ...
-
文件中肯定存在一些差异。 如果长度不完全相同,则散列将不同。 您可以使用比较十六进制编辑器(例如Hex Workshop)来查看差异的确切含义。 我想到的可能性: 正如@orn所提到的,你正在使用的zip格式可能有一个时间戳(不确定)。 文件添加到存档的顺序可能不同(取决于您选择它们/构建源数组的方式)。 There is certainly some difference in the files. If the lengths are not exactly the same, the hash wil ...
-
好吧,通过调整响应输出流和缓冲,我得到了一个解决方案: using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Web; using System.Web.Mvc; namespace MyProject.Controllers { public class ...