I have an "open" command where the user can chose a file. 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 in a specific region. My DataView
gets its DataViewModel
via DI. Now my problem is how do I pass the selected filepath to the NEW (created after file is chosen) ViewModel?
My first approach seemed clever and worked as long as I only created one View
. But since I create multiple views (Tabs) the following approach does NOT work because I cant compose the same value more than once.
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)
{ }
Is there any other way to inject / pass my string parameter to the viewmodel?