When using InteractionRequestTrigger for showing a custom popup view, the same instances of the View and ViewModel will be used each time it's shown. How can I recreate/reset the View/ViewModel, so the state of the View is "as default". The problem is that I use a TabControl in my popup, and the last selected tab is still selected after I close and reopen the popup.
Any ideas?
Here is method that won't require you to create a new set of nuts and bolts.
Implement IInteractionRequestAwareon your view model.
Create a integer property on the view model to store the index of the selected tab
Bind TabControl.SelectedIndex to the new property
In the implementation of the IInteractionRequestAware.Notification setter, reset the selected index property to 0.
You have to create your own PopupWindowAction. Add a property for the WindowContent Type and use that to create the new instance every time you show the popup.
Related
I'm currently developing a WPF application using the MVVM framework. And I have this functionality:
I have a main window which has a combo box and frame (where I put my pages) and a view model. One of the pages in that frame is where a user can add a data and these data are used to populate the combo box in the main window. My problem is how to automatically update the items in the combo box after adding a data from that page. Btw, this page has a different view model too.
Thanks.
You can establish an event in the page viewmodel for changed data. Then subscribe to those events within the window viewmodel and update the combobox items accordingly.
You have access to the parent window from iframe via window.top. You have to write this code in your page what you have loaded in iFrame.
window.top.document.getElementById("combobox_element_id").value='Your New Value';
best of luck
You can pass the Source DataContext of ComboBox (ObservableCollection) to page ViewModel so you can simply modify the collection from Page view model.
I have created a custom control with new dependency property (TagToSet) of type MyTag(id, name, value).
After adding this control to my window design, and going to the properties to set the value of the new dependency property. Here I want to open a dialog to select the Tag that I want (like the case when the dependency property is collection).
note: the Tag property is not a collection, and the required dialog should connect to a WCF service to list the available tag.
Thanks
Ok, here is the start key Microsoft.Windows.Design.PropertyEditing
for those who are trying to do like me read this
article
How can I reset my viewmodel when the user clicks new button on the view that has the viewmodel as it's datacontext?
For example:
If I have a view NewCustomer and upon save, the data is saved to the DB and the newly created account number is displayed. But when the user clicks the New button in the screen, I want the view (viewmodel) to be reinitialized. Or if the user clicked cancel in the screen to clear all changes.
How can I achieve this? I am using Prism 5.0 and Unity as my container.
If I used IRegionMemberLifetime, I can clear the viewmodel data when I navigate away and navigate again to the view (by setting the KeepAlive as false on clicking New button before navigating away). But I want the form to be cleared without navigating. Can this be done?
You could have a screen/workspaceViewModel, and another ViewModel wrapping your data.
So two classes: CarScreenViewModel and CarViewModel.
The CarScreenViewModel would have a property, say CurrentCar, which reflects what is currently selected in the screen. Then, when clicking the Create button, you simply set:
CurrentCar = new CarViewModel();
Resetting partially loaded data will only lead to behaviour that is hard to reproduce. It is better to start with a fresh instance.
Your standard approach will be something like below
ViewModels
CustomersContainerViewModel which contains
a collection of CustomerViewModel s
and ICommands like
CreateNewCustomer
DeleteExistingCustomer
UpdateExistingCustomer
Your View will contain
the CustomersContainerView which will contain
a collection of Customer Objects in your required UI element
a button to Create new customer (which will launch a new screen which contains the newCustomer fields it can also contain cancel, which will just close the form)
a button to delete (can also be a ContextMenu)
a button to update (can also be a ContextMenu) which will launch a customer form filled with details from DB.
Hopefully this makes some sense... Let me know if you have problem with any of the above
Update - Forgot to add. NewCustomer Command will add a new Customer object to your CustomerCollection and that should open a NewCustomer form (or whatever you chose) for user to input the customer details. Cancel/Delete will just remove that record from the collection. Delete will update the DB as well in addition
In my case
yourViewName.variableName.postValue("")
I have a Silverlight 4 application that uses multiple tabs. On Tab 1 I allow the user to select items from a grid, right click and select a context menu item that sends the items to a different grid on Tab 2. However, if the user has not clicked on Tab 2 yet, the grid I am trying to add items to does not exist yet.
What is the most elegant way to make sure that all objects on the second grid are instantiated even if the user has not selected the tab yet?
Thanks,
-Scott
Assuming you are adding items to data grid of some sort then the way to go is to add your items to an ObservableCollection and then data bind the grid to the collection.
That way you don't have to worry about whether the grid is actually visible or not and it will update itself when it does become visible.
Instead of trying to prepopulate the grid on tab2 with data that does not yet exist, you could use the MVVM pattern.
Tab1 could be view1 of viewModel1. Tab2 could be view2 for viewModel2. When view1 updates viewModel1, ViewModel1 updates ViewModel2, which, in turn, updates view2. Then, you only need to set bindings for the visibility, isEnabled, and ItemsSource properties.
I have a series of views that are to be displayed depending on the currently selected item in a tree within a parent view. These views are created and registered with the region during the initialization method of the parent view and are being correctly deactivated/activated, therefore giving the effect of swapping in/out the correct view. These views have a single underlying viewmodel as their datacontext, which contains data objects supporting INotifyPropertyChanged.
This solution works if there are no currently outstanding edits in progress within the child view but if there is a edit in progress in a view (i.e. the user has changed the contents of a description but hasn't clicked out of the text box) and that view is deactivated (i.e. the a different tree item is clicked within the parent view, thus causing a de-activation to occur) a NullReferenceException is being thrown in the NotifyPropertyChanged() of the underlying data object attached to the now deactivated view.
What seems to be happening is this:
An edit is started by the user in the child view
The user clicks an item in the tree in the parent view
The controller picks up the change in the selected item in the tree
The current child view is deactivated
The new view is activated
The change from the edit happens to the underlying data object (the set method is getting called)
A change notification event is generated by the data object as a result of this change
A null reference exception is thrown.
Presumably, this change notification event is being sent to the now de-activated view, but the view is not null.
I have not tried this myself, but I believe one solution was to listen for the deactivate event of the view using IActiveAware and cancel any editing.
See if this link helps.