Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top