【发布时间】:2011-11-05 06:27:08
【问题描述】:
我有一个“打开”命令,用户可以在其中选择一个文件。 When the file is chosen (and therefore I have got the filepath as a string) I get a new instance of my DataView (with the NonShared and CreationPolicy attributes) out of the CompositionContainer and display it在特定区域。我的DataView 通过 DI 得到它的DataViewModel。现在我的问题是如何将选定的文件路径传递给 NEW(在选择文件后创建)ViewModel?
我的第一种方法似乎很聪明,只要我只创建了一个 View 就可以工作。但是由于我创建了多个视图(选项卡),因此以下方法不起作用,因为我不能多次组合相同的值。
if (fileDialog.ShowDialog() == true)
{
Container.ComposeExportedValue("FilePath", fileDialog.FileName);
IRegion contentRegion = regionManager.Regions[Regions.CONTENT];
contentRegion.Add(Container.GetExportedValue<IDataView>(), null, true);
}
[ImportingConstructor]
public DataViewModel(IRegionManager regionManager,
[Import("FilePath")] string filePath)
{ }
还有其他方法可以将我的字符串参数注入/传递给视图模型吗?
【问题讨论】: