Creating view programatically

May 31, 2012 at 9:14 AM

I am trying to work around this issue in a WPF application, but I have not much result as yet.

Here is the problem :

I have a MainView with a tab control and 3 tab items.

Each tab item calls a different view and its view model. In one of the view model (ContactView) I have an "Add" button. I would like this button to add a tab item in the tab control of the mainView.

I created a messagebus from the ContactViewModel to the MainViewModel for this "Add" action. This work fine. But my problem, is that I don't how how to programatically create the new tab item on the mainView as the mainViewModel who receives the message does not know about the view.

Is it at all possible? And if so, how?


I thank you in advance for your answer.

May 31, 2012 at 6:40 PM

I found the answer to my question after reading other discussions on similar subject.

This is what i did:

In ContactViewModel I SendMessage. In the MainViewModel I registered for the message, then I created an EventHandler to notify the view, and in the view I call the event from the view model which will create my new tab item.

I am really starting to get the hang of this great frameworK