MVVM Light messaging from child to parent - mvvm-light

Is it possible to raisepropertychanged for an ObservableCollection from a child viewmodel ?
I have a child viewmodel which inserts a new item in a ObservableCollection from a parent ViewModel and I need to raisepropertychanged on that collection for refreshing a list binded to it.
What I need is to view in that list the new item already added.
Thank you

You can Use Messneging service to send and register Value form one view/ViewModel/Class to any View/Viewmodel/Class. You can use like You can use the Token while sending and registering Messaging.
Suppose You have to pass Message From ViewModel to ABCView then you can use Messenging like this..
For Ex:
Messenger.Defalut.Send<ObservableCollection<string>>(obj,"ForAbcView");
And in ABCView you can register like this:
Messenger.Default.Register<ObservableCollection<string>>(this,"ForAbcView",(b)=>{ //Some Code });
With using Token the Messenger Sender will only looks for the Register which will have same token. It only calls the method which will have same tocken.
This way you can send the collection to any palce You want.

Related

Messaging Centre - Subscribing Event in the ViewModel Constructor

I am trying to send data from one ViewModel to another using Messaging Centre.
I have subscribed the event in 2nd ViewModel's constructor. But the event is not subscribed as the constructor is not compiled until I open the page/view corresponding to the ViewModel.
I am using MVVM Light, until now I had an understanding that the VM's constructor are compiled when ViewModelLocator is called at the app startup.
Can someone help me understand this better and how can I subscribe the event i.e. compile the constructor without the VM being called.
Perhaps you are thinking about this in the wrong way. Without seeing code it's difficult to see what you are trying to achieve exactly, but what you could do is subscribe to the event elsewhere in your app, for example in your App.xaml.cs. When the event fires, at that point navigate to a new page of type ViewModel2 and pass any details required as a navigation parameter.

Refreshing caller listpage form

I need to call parent form but my parent form is a listpage form.
As I know I can't add new methods to list page forms i need to add this method to the interaction class of related list page form. But I do not have an idea how to do it.
Would you have any suggestion for me?
You have two options:
Set the AutoRefreshData on the menu item on the list page. This will refresh the list page, I am not sure when (maybe it works best on action menu items).
Call element.args().record().datasource().research(true); from the child form.
You can refresh a datasource of a calling record.
You need to cast element.args().record().datasource() to FormDatasource so you can call research() or executeQuery() depending of you needs.
Also you can/must check if record is from a form by using method on common isFormDatasource(). If this is true than this record is from form.
If you need to refresh parent from another form you should do it in closeOk() method of this form or at the end of you logic in a class.

In Watch Kit How Do You Present A Page Programmatically

In a watch app how do you change page programmatically?
I've got 3 WKInterfaceControllers in a page based app and I want to change from one page to another when a user presses a table view cell.
I can present a view controller modally fine but when I try to push the view controller or hook the segue up to the cell controller, nothing happens.
You won't be able to push an interface controller since you're building a page-based app. The only option that you have is to use the WKInterfaceController becomeCurrentPage method on the interface controller you want to switch to. It needs to be one of the three interface controllers already loaded into the page set.
Since you don't actually have a reference to the interface controller that you need to switch to from the table interface controller, you'll need to use a system such as NSNotificationCenter to send a notification to the interface controller that you need to becomeCurrentPage.
This should allow you to switch from one interface controller to another when tapping on a table row.

How to handle Ctrl+n on a list page form?

I am trying to handle "ctrl+n" (create new record) action on a list page. I would like to start an wizard after ctrl+n is started. On a normal form I can do it on datasource in create() method. Methods on datasources are disabled on the list page. I can not find a way how to do this. I know it is done somehow on a PurchTableListPage but I can not find how.
How this action can be handled on form with listpage template?
It is on design "newRecordAction" property.

Asp.Net MVC Not Duplicate forms when Edit/Add

When we have anything that requires user input (Eg adding a product to a database) the Edit screen looks the same as the add screen. When using MVC .Net how do you handle this? Do you return the same view? Just adjust the model to reflect the change?
Same (partial)view
You create only one but strong typed view (depending on the UI it can of course be a partial view as well). When adding new data return this view from controller action with default model object instance (usually just a new instance without any properties being set), but when you edit, return it with the object instance that you'd like to edit.
Controller part
Regarding controller actions you can have four of them:
Add GET
return View("SomeView", new Customer());
Add POST
Edit GET
return View("SomeView", new CustomerRepository().GetCustomer(id));
Edit POST
Bot GET actions return the same view but with different model as described earlier. POST actions both store submitted data, but return whatever they need to. Probably some RedirectToAction()...
You can use the same view for display and Edit, simply call it from your controller
return View("ViewName")
You could have the form fields in a partial view and have two separate views using the same partial view, one posting to the edit controller action method and the other posting to the add controller action method.
Partial views are used to remove duplicity. You could read an example of this in the Nerd Dinner tutorial.

Resources