Xamarin.Forms pages, views and viewmodels - xamarin

I’m quite new to mobile development.
What is the difference between page and view?
From what I understand a page is a container of views, which in turn, if the MVVM pattern is implemented can have an associated ViewModel.
In this scenario, the page does not have an associated ViewModel.
Is it right?
Thanks

Page is used when creating different screens (pages), such as LoginPage. View is a UI interface that can be embedded in a page. In MVVM, the view is notified when the properties of the view model change. Both page and view can be data bound.
For more information about MVVM, you can refer to: The Model-View-ViewModel Pattern | Microsoft

Related

Xamarin dynamic forms

The idea is to create an app in Xamarin with dynamic forms. The form definition is taken from any source like local DB or Web API.
The definition contains the set of fields and theirs's default values.
Currently my question is about view model.
Let's say the situation is clear with a view. I mean that user controls can be added to a view programmatically based on the form definition.
But how view model should look like in this case?
As a set of dynamic properties ? How to support user controls binding to respective view model properties ?
Any ideas or links to respective articles are welcomed.
Thank you in advance.

Xamarin Forms - Access Prism INavigationService in View Model for Content View

As part of a Xamarin.Forms application I have implemented a custom navigation header. The Navigation Header is simply a Content View that has its own View Model. Pages which need to participate in the navigation experience of the application include this content view within them.
This application is using Prism 7 and to perform navigation within View Models I would like to use the Prism INavigationService. The issue I have with this is getting a reference to the INavigationService inside the View Model for the navigation Content View.
Accessing the INavigationService in a ContentPage is trivial, simply have this injected using constructor injection, the problem is that injecting INavigationService into the View Model for a Content View is not possible using prism 7 - this is confirmed by Brian Lagunas in his reply to this topic on the Xamarin Forums.
In his response Brian quotes as follows:
You can't inject the INavigationService into a ContentView's VM. You should either expose a property that you can bind to from your VM, or set it in code when the ContentView is loaded.
With the above in mind, what would be the approach to getting a reference to the INavigationService in the View Model of a Content View? I already have the wiring of the Content View to its View Model working correctly.
You already mentioned that there is no way to use INavigationService in your View Model for Content View (your custom control).
One of the easiest and simplest ways to resolve this is by adding bindable command in your Content View (custom control), having this bindable command you will be able to use that command and bind to it from ViewModels of your pages.
With this approach you can use INavigationService in your page ViewModel in a standard way and navigate from page based on command execution in your ContentView.
In other words you can handle your navigation from ViewModel when that command from reusable view is executed.
There is a lot of examples how to achieve this, you can use this one from another SO thread.
Wishing you lots of luck with coding!

Using container view with Xamarin and MVVMCross

I am trying to use a Container View within a View Controller (Free Form View) to reuse some components that are common for two views. So far I have a View Controller (Free Form View) with a Ui View and a Container View. Upon opening up the Free Form View, Container View should contain Free Form Purchase View, but when pressing the blue Button, that View should be replaced with the View last View Controller. I have a similar setup for Android where I use Fragments.
I am looking for the best way to navigate between the controllers. I use MVVMCross throughout the application, but I am open to other suggestions that does not involve MVVMCross.
you need to create your own controller which handles swapping of Views in Container View through custom Segue implementation.
You can find detailed step how to do this from Richard Woollcott post: Using the ContainerView to Transition between Views - aka More Fragments in Xamarin.iOS

Spring MVC jsp view

To design views that each jsp views have common navigation menu ( a treetable, when clicking on a tree node it navigates to another page) what is a good approach for this?
Adding a new node to navigation menu will effect all pages.
Navigation menu tree nodes will be populated from db (a menu table on db)
Is it possible to cache menu view on client so navigation menu will not be populated each time user navigates another page?
Thank you
There are two separate questions asked in the post, I will answer them accordingly:
1) I would recommend using a Template Engine which integrates with JSPs.
Apache Tiles fits in this category. Using this framework, you can define template which contains common sections for header, footer, body and menu layouts. Furthermore, it supports derived templates via inheritance.
2) Caching solution : Since you want to load values from database to make the menu dynamic, caching and pre-populating the menu will minimize page load times. This should be done on server side.
A separate thread/process should be made responsible for pre-populating and refreshing cache periodically.
From clean code perspective, JSP or Tiles template should not invoke database calls. Instead the page should interact with a DAO/component to separate concerns and ensure MVC pattern is not broken.
Helpful links:
Tiles Example
Thymeleaf - an alternative to Tiles

How do I create a user control view in MVC3, create events and reuse it in other views?

I am new to MVC3. In asp.net user control, its fairly easy to create a user control that has a combo box with a button, with hover over event, and a collection property of combo box that then displays a list
how do i achieve this user control (partial view) in mvc3?
What you are looking for is helper methods. You can see a good explanation of it here. In that post, there is a great link for how to do this: Creating Custom HTML Helpers.
I am also a WebForms developer originally, and I had a hard time making the connection between user controls and HTML Helpers. This should give you enough guidance to get started with what you want.
Hover over event can be done using jQuery, your combo box just needs to have a CSS class in the partial view and then the even can be hooked up to that selector.
The Collection property will be inside the View Model that your partial view binds to.

Resources