I'm am having trouble finding out how I would create an instance of a view model and set that as the view model of a view am I am going to navigate to using the Silverlight navigation framework.
for instance, If I have a list view with a view model, I would like the list view to use the navigation service to navigate to the details view and and set the view model of the details view to the same instance of the view model that the list view is using.
From what I have read and understand, there is no way to pass data along when using the Navigate method. And the navigate method does not return the instance of the view that will be navigated to?
So my question is... Once I have used .Navigate(URI) to navigate my silverlight application to the detail view, how can I set the viewmodel of detail view to the instance in list view before i navigate away from the list view.
First of all, your statement "From what I have read and understand, there is no way to pass data along when using the Navigate method" is incorrect. You can pass simple data values via parameters.
You can also share a datacontext between views by using a navigation frame. Check this SL3 article out:
http://timheuer.com/blog/archive/2009/04/03/share-data-between-navigation-pages-in-silverlight-3.aspx
You can use the query string to pass parameters to the view you want to navigate to, then use those parameters to create the ViewModel.
here is a post about "Site Navigation Basics in Silverlight 4" that shows how to use query string parameters in Silverlight navigation.
Related
I've converted my storyboard that uses split view controller to size classes using xCode 6 beta 3. Upon running the application, I see that the detail panel shows up first and has a "back" button in navigation. That button brings me to the master view. However, I cannot navigate back to detail view controller from master.
Is there a way for me to keep using master/detail approach in a universal storyboard?
i am developing a trigger.io application using backbone, the entire app is in one page but i need to open a detail page in a new window (not a modal view, a tab in android).
I don't know if it's possible to render a view in a new window, or write to history the view and navigate to the url.
Can anybody give me some tips.
Thanks
If you want to open a special view, specify a route calling this view.
Now you create a simple link with target blank to the route.
The application gets started in the new window and loads the action mapped to the route.
I think this is the best solution to do this, although there are ways to create windows and communicate between them in JavaScript. If you need to control the new tab, e.g. closing the tab or act on its content you are forced to create the new tab by javascript and keep a reference to the new tab.
Have begun a WPF app following mvvm pattern and have hit an issue. I have a Customers page which has a number of searches and returns a list of customers. When I double click a record I want to be able to navigate to the Customer view so user can view/edit details.
Is this possible without using MVVMLight or WAF or PRISM(as I have struggled for a bit getting head into PRISM fully!!!) without forcing my view model to have knowledge of my application?
Thanks
Some people use Dependency Injection to connect VMs with Views in a decoupled way. Take a look at Unity
I would use a seperate / underlaying shell view & viewmodel with just the structure of your ui layout (some grids for positioning navigation, menu, search or content areas)
Then position your application views / controls the shell view. (maybe with some Visibility Bindings)
The main purpose of the shell viewmodel is to coordinate the flow of your ui. For example what control should hide or show based on some events of its child controls.
You could use an eventhandler in your search, wich is registered in the shell viewmodel, to show / hide your different content views.
Another approach could be a ContentPresenter.
My silverlight application has 2 pages, PageA and PageB. Each page is binding to it corresponding ViewModel, PageAViewModel and PageBViewModel. (I set ViewModel to View's DataContext inside xaml.)
User can switch back and forth between these pages, when user switch between these pages they create new instance of PageA and PageB which also create new object of its ViewModel which I don't want. I try to set NavigationCacheMode to Enable, now all Views create instance only first time user navigate to that page this also mean ViewModel has only one instance.
I want to know how to control UI to create only one instance of View and control when to create new instance of its ViewModel?
This is where IOC (Inversion Of Control), like Unity, comes in handy.
You would simply register the ViewModel as a singleton (one only, ever) with Unity.
Rather than embed a ViewModel in the View (really bad practice to hardwire them like that ), you specify what type of ViewModel the View wants when it is created and the matching ViewModel would be "injected" into the view.
Basic MVVM, without some other injection framework, does not give you much out of the box (aside from a separation from the view).
Have you tried using MVVM light framework for your application. It supports a view model locator concept which avoids recreating the instance of your VM each time a user clicks on a page. Take a look at a presentation by Laurent Bugnion here.
Hi im developing an winform application using mvc pattern,
If i have a windows form as a view with a button in it, and i want to show another view(winform) on click of button in the first form.
In this case whether the view should should notify the button click to the controller and the contoller will instantiate the second form and show or the first view itself will do this.
The controller should probably handle it. In the purest form of the MVC pattern, views should be for displaying their own content, and any other logic, including displaying other views, is up to the controller. (In fact, for many actions, that is all the controller ends up doing.)