Question

I have the following code as the constructor of a ViewModel class:

    [ImportingConstructor]
    public ItemDefViewModel(IItemDefView view)
        :base(view)
    {
        _Item = new ItemModel();
    }

This view model corresponds to a child window. When I run the child window once, close it and the try to run it again I get an exception telling me that I can't call Show, ShowDialog on a closed window. Does this mean that only 1 IItemDefView object is created? How should I go about this?

Était-ce utile?

La solution

By default, MEF registring instances in container as singletones. To change this behavior, you need set property RequiredCreationPolicy in ImportAttribute to NonShared. See ImportAttribute.RequiredCreationPolicy Property, Parts Lifetime

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top