Caliburn Micro Framework Windows Phone 8 usage Research (ii) page navigation

Source: Internet
Author: User
Tags naming convention

Background

For the MVVM architecture of the WP program, a very important problem is the navigation, as well as navigation parameters. Experienced people know that WP navigation can only be done in view, and navigation parameters can only be obtained in navigatedto and other view events, so we have to add processing in the Xaml.cs file to get the navigation parameters and then construct the ViewModel by navigation parameters. The process was painful because we had to switch back and forth in two files to see our logical code.

So next we'll look at the great thing about the CM writer (admittedly, really bad),

Let's look at what navigation looks like in the CM frame:

With no parameters:

Define the following functions in ViewModel:

The two lines cover a lot of information, and we first look at the questions that will exist when we first see these rows:

1, what is Navigatoinservice?

This member is defined in this way:

It is easy to see through the code that, by relying on injection, Mainpageviewmodel will get the object case of the Inavigationservice interface type (cm takes the container for object acquisition, As mentioned above, we define a container in the bootstrapper, where we do not unfold, and the reader clearly obtains the example.

2, what is Urifor?

CM's page navigation is based on viewmodel navigation, since we call Urifor<actionpractisepageviewmodel>, then after invoking Urifor, CM internal is automatically positioned within the Actionpractisepage.xaml defined in the project (note: This locates based on the naming convention, the naming rule needs to match the Apage.xaml->apageviewmodel) and automatically constructs the URI of the navigation.

3, Navigate?

This function is the action that the navigation performs, Once you find Actionpractisepage.xaml, you can navigate to this page, and CM will get Actionpractisepageviewmodel again through container, and ViewModel automatically binding to view.

4. What about the others?

In fact, the amazing thing is that we can even delete ActionPractisePage.xaml.cs, because the Actionpractisepage InitializeComponent () is automatically invoked after the navigation within CM. Complete the construction of the page. So our engineering catalog looks like this:-)

5. Do you need this line of code?

The previous reference to navigation will result in a case of viewmodel via container, so we need to configure Actionpractisepageviewmodel within bootstrapper:

Looking good, we can navigate and navigate based on ViewModel in ViewModel via the CM-provided navigation. The call is very concise, fluent interface makes the call is also very easy, error-prone.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.