This project is read-only.

Secondary view loaded at runtime

Feb 23, 2014 at 7:05 PM
I have a view laid out using the Primary-Secondary layout style (there is no list).

I need to load the secondary view at run-time dynamically depending on some condition.

What is the best way to achieve this, and if possible in a way that the dynamically loaded view can have it's own view-model that is located by the framework and can act like a typical view in all aspects, for example it automatically picks up actions defined in its view-models.

Thank you again and again,
Regards
Feb 24, 2014 at 1:55 PM
Hello abnajjar,
From your description you may want to look into Partial Views (http://codeframework.codeplex.com/wikipage?title=Partial%20Views%20in%20CODE%20Framework%20WPF&referringTitle=Quick%20Tips). A Partial View will allow you to embed it into another view, while being a self contained ViewModel/Actions.

It's a bit difficult to tell from your requirements if the dynamically loaded view may be different (i.e. in certain conditions it may be a customer, other conditions it may be a product), but you could accomplish this by having both partial views defined on the Primary-Secondary layout, then showing/hiding the appropriate on based on your criteria.

Jeff
Marked as answer by abnajjar on 2/25/2014 at 1:51 PM
Feb 25, 2014 at 4:44 AM
It really depends on when you are deciding what view and view-model you want to load. Do you know the conditions before you load the view? If so, you can just call a different method within the controller? If it needs to go to the same method in the controller, the controller can make the decision and return different views and view-models. Or, if it is even later, then Jeff's suggestion about partial views may be a good way to go.


Markus
Feb 25, 2014 at 7:00 AM
I have considered using partial views, but I am still not very resilient with the framework as I am a newcomer.

I will try the different ideas you have suggested and see how they fit best with my case.

Thank you so much
Regards
Feb 25, 2014 at 9:52 PM
TexasJetter wrote:
Hello abnajjar,
From your description you may want to look into Partial Views (http://codeframework.codeplex.com/wikipage?title=Partial%20Views%20in%20CODE%20Framework%20WPF&referringTitle=Quick%20Tips). A Partial View will allow you to embed it into another view, while being a self contained ViewModel/Actions.

It's a bit difficult to tell from your requirements if the dynamically loaded view may be different (i.e. in certain conditions it may be a customer, other conditions it may be a product), but you could accomplish this by having both partial views defined on the Primary-Secondary layout, then showing/hiding the appropriate on based on your criteria.

Jeff
Thank you, I found a way to do it using Partial view, but I have found a few issues in the framework itself that might
need improving, I have posted another discussion on this if you like to comment.

Regards
Feb 25, 2014 at 9:56 PM
MarkusEgger wrote:
It really depends on when you are deciding what view and view-model you want to load. Do you know the conditions before you load the view? If so, you can just call a different method within the controller? If it needs to go to the same method in the controller, the controller can make the decision and return different views and view-models. Or, if it is even later, then Jeff's suggestion about partial views may be a good way to go.


Markus
Yes, I know before hand (the minute I call the Controller Action method) which views should be composed together.

I was able to find a solution using partial views, but I would like to know how could it be solved otherwise from inside the controller.

In other words, how could a controller compose multiple views together, or how would you go about solving this ?

Thank you

Regards
Feb 26, 2014 at 2:06 AM
If you are composing a view out of others, the partial views may just be what you want. If you are looking to load completely different views, you could call either different methods on the controller or return different views from the same controller method based on some condition. Note: return View() has an overload that takes a view name as a parameter.


Markus
Marked as answer by abnajjar on 2/25/2014 at 10:39 PM