I know that view controls should not be present in ViewModel, but in one specific situation I have to send a button object from one assembly to another. Is it ok to make at least a property of type 'object' like below in ViewModel?
public object StoreButtonControl {get;set;} // for storing the button
Or does it break the MVVM?
Related
I've got a Silverlight client and I'm using MVVM. I've put in my first View and View Model. The View binds to the View Model. I now want to localise the text of all the controls. For example my View has a button which contains the text "Search". I know I need to bind the Text content property of the button to something to provide the correct text. The question is what? Do I provide a property in the View Model called SearchButtonText and bind it to that(where the SearchButtonText property returns a resource string)? Or is this taking it too far in terms of what the View Model does and instead bind to a resource string in the View namespace, even though the root level binding for the View is the View Model?
Any help much appreciated!
Cheers
Bind to a resource string in the view.
I have a view which contains a menu, it allows you to browse 5 different sections depending on where you click. When you click you are not changing page, you are hiding the other sections and showing the one you asked. It is required that everything occurs under the same Place.
From the View is simple and clean as each section is a different class and visually they are mutually exclusive. I access the controls of each section by "getting" the section itself
From the Presenter is a mess, I am having to register the handlers on the onBind() method for all 5 sections on that single presenter class, and all the logic of the events goes there as well, event handlers are beginning to conflict with similar names.
How can I break down the Presenter as I'm doing with the Views?
view Example
public interface MyView extends View {
public DeviceSettings getDeviceSection();
public Reports getReportsSection();
public License getLicenseSection();
public Support getSupportSection();
}
You can create PresenterWidgets/Views for each of your sections and then inject them into your MainPresenter.
You add handlers to your menu and then based on what is clicked just add/remove the corresponding PresenterWidget to your content slot.
You can check out the nested presenter example.
i have a view which is fetching data from an Array and presenting the data in a tableview. This view has a navigation controller with a button in it. The button is meant to take you to another view for advanced searching. Let's say that in this new view i have a picker, when the user selects a value from the picker and clicks the back button in the navigation bar i want to get the value that the user selected. What is the best practice to do that? How can i send the selected value from one activity to the previous one?
Thanks in advance.
What you need here is reasoning a bit in terms of the Model-View-Controller design pattern.
Views should get their data through the model. So in your advanced search view, when the user selects some value, this value is stored in the model.
When you go back, the first view redraw itself by reading the current search value from the model.
There are other possibilities, like having the search view controller own a pointer to the first view and sending a message to it when the search value changes, but this is not very modular and is pretty fragile.
Use delegation. Write your own protocol like "PickerViewDelegate". then implement this protocol in your "main view" (which has table view). in PickerView just invoke [delegate somethingPicked:something].
I'm not sure, that search value is a model entity.
I've got a prism/mvvm view and want to notify the ViewModel if the View has got or lost the focus.
I'd guess I'd need to bind GotFocus of the View to an action in the ViewModel, but I got no idea how to get started on this.
Sure this is a standard problem which has been solved somewhere, and it's just me not finding the solution?
You could use InvokeCommandAction behavior. This behavior is defined in the assembly System.Windows.Interactivity which is part of Expression Blend. With this behavior you could bind to the GotFocus event of your view and execute a command in your viewModel.
The same approach can you use for LostFocus. Here´s an example how to use InvokeCommandAction.
One thing about GotFocus of UserControl. You should know that the GotFocus event of the View is raised when a control, such as TextBox, gets the focus. You can´t focus the UserControl by its self.
[Update]
GotFocus of the UserControl is raised when IsTabStop is set to true
Can´t you use the IActiveAware interface of the prism framework. The IsActive property gets set when the view gets navigated in the region.
The interface can be implemented on the View and the ViewModel (requires that the viewmodel instance is set as DataContext of the view) to be notified when the view is activated in the region.
i have a view with label when button pressed moves to second view controller with a picker view , i need to retrive the selected value and then to pass to first view's label,
i have used delegates and protocols to acheive this,
but is there any possible ways like referencing like etc to do this?
You can use a singleton class to store the selected data and then can retrieve it wherever you want. Just like you get UIApplication's instance from 'sharedApplication' method, its the same object in the memory through out the application lifecycle.