ViewModelManager.UnregisterAllModels

Topics: Feature requests, Questions
Jan 29, 2013 at 7:56 AM

Is it possible to Unregister all Models of a type of a viewmodel?

Feb 3, 2013 at 2:15 PM
Can you give an example of this? Normally this happens when the view model is closed.

What do you want to achieve:

1) Call cancel on the models
2) Call commit on the models
3) Just set them to null

Internally the models are already available in the view models, but if you can give me an example on what you have trying to achieve, I can guide you a bit better.
Mar 8, 2013 at 10:17 AM
Edited Mar 11, 2013 at 7:59 AM
Ok lets try to explain.

You write: Normally this happens when the view model is closed. Ok and how is it possible to close a viewmodel?

The Viewmodelmanager holds the references from the model an the viewmodels. So I want to say close all viemodels according to a special group.
Mar 10, 2013 at 12:24 PM
Is the group a logic container of views of are they being used all over the application? I can't think of a practical example. If you could create a sample, then maybe I can understand what you are trying to achieve and let you know how to accomplish it.
Mar 11, 2013 at 7:57 AM
Edited Mar 11, 2013 at 8:22 AM
I think i already explained in an other discussion. The problem with the isuee "Delete the viewmodel"
The example with the house and rooms. I want to load other rooms. So i have to close all viewmodels for the existing rooms.
Mar 20, 2013 at 2:37 PM
No ideas?
Mar 22, 2013 at 3:14 PM
No, because I simply cannot understand your requirements, no matter how you try to explain it. Maybe if you have an actual case (app) that shows what you mean, I cannot help you further.
Mar 22, 2013 at 4:00 PM
Ok lets give you a little bit of code.

On several Views I wan't to show Rooms. When the pages change I don't wan't to close the viewmodel.

For example:
public RoomDetailView()
{
       InitializeComponent();

       CloseViewModelOnUnloaded = false;
}
public RoomGeneralView()
 {
        InitializeComponent();

        CloseViewModelOnUnloaded = false;
 }
Both views implements this method:
protected override IViewModel GetViewModelInstance(object dataContext)
 {
       if (dataContext is Room)
        {
                var model = dataContext as Room

                var manager = ServiceLocator.Default.ResolveType<IViewModelManager>();

                var vm = manager.GetViewModelsOfModel(model).SingleOrDefault();

                if (vm == null)
                    vm = new RoomViewModel(model);

                return vm;
            }

         return null;
 }
Now I want to change the house
private void OnActiveHouseChanged(object sender, AdvancedPropertyChangedEventArgs e)
{
     // delete the old room models
     // get new Rooms (models)  from the database.
     
      But now I have also to close the old viemodels
    
     var manager = ServiceLocator.Default.ResolveType<IViewModelManager>();
     manager.Close(typeof(RoomViewModel)   // somethink like that !?
     ///
}
Is it now more clear?
Apr 2, 2013 at 1:14 PM
:-(
Apr 2, 2013 at 1:22 PM
We are terribly, terribly, terribly busy. Paying customers always get a higher priority. It's on the backlog, but there are a lot of other customers waiting as well.

1) It's open source, you can do it yourself
2) Be patient
3) Pay someone to do it for you
Jun 19, 2013 at 6:48 AM
Can I add an issue to this problem?
Jun 19, 2013 at 8:07 AM
Of course you can, all issues are the backlog. Please try to describe what you want as good as possible.
Jun 19, 2013 at 9:05 AM
Yes. But thats the problem. I don't know at the moment if you realy understand my problem.
Maybe its only my lack of understanding. Maybe there is an easyer solution.

An easy description:

I need an container which holds the references to viewmodels. Then I wan't say to this container: Close all viewmodels with an special type, or name, ...
Or order the viewmodels in groups. So i can say close viewmodels in group xy.

My example: You have a house with nested rooms and nested furniture . So no please close all furniture Viewmodels because I need new furniture.

Is that a understandable description for an issue?
Jun 20, 2013 at 10:52 AM
Yes, good description.
Jun 20, 2013 at 12:45 PM
Ok. Added :-)