WPF Practice 7: mvvm light Toolkit (VII. Messenger)

Source: Internet
Author: User
Tags visual studio 2010

Keywords: WPF. Net C # mvvm light Toolkit framework Visual Studio 2010 vs2010 expression blend 4 getting started tutorial New Practice

VII. Messenger

A user-friendly logon interface should be able to record the user ID of the last logon to avoid meaningless Repeated input. To achieve this function, I will continue to process the previous login page.

1. In loginviewmodel. in CS, add a relaycommand property loadedcommand as the command object for loading the completion event on the Response view layer page, and initialize it in the constructor (pageloaded () the specific implementation of the two moveinputfocusto methods involved in the method will be detailed later ).

2. In blend 4, select "behavior" from the list on the "assets" tab, drag "eventtocommand" to [Page], and change the default name to pageloaded.

3. Bind the command attribute of pageloaded to loadedcommand (note that the eventname in the "Trigger" column in the "properties" tab should be loaded), as shown in the following two figures.

4. Assume that there is a loadlastlogininfo () method in the user class of the model that reads the user ID of the previous logon from the configuration file every time a new user object is constructed, the loginpage at the view layer determines whether the input focus should be in the user ID input box or password input box based on whether the user ID input box has a value. However, no input box can be bound to the viewmodel layer to identify the element and obtain the input focus. To do this, you must call the focus () method of the element. The problem arises: I don't want the viewmodel layer to know which interface elements need to get the input focus. To avoid the tight coupling between the view layer and the viewmodel layer, I need to use the messenger of mvvm light toolkit to remove strong references between them. First, create a new class movelogininputfocusmessage, which contains a string type attribute inputfieldname.

5. In loginviewmodel. CS, implement the two moveinputfocusto methods (message senders) involved in the pageloaded () method ).

6. In loginpage. XAML. CS, modify the loginpage constructor, register the message receiver, and provide the movelogininputfocus () method as the specific implementation.

Compiled.

Author: Li fengtong; Source: http://www.cnblogs.com/phoenixtrees. Http://www.cnblogs.com/phoenixtrees/archive/2011/05/10/2041921.html

Keywords: WPF. Net C # mvvm light Toolkit framework Visual Studio 2010 vs2010 expression blend 4 getting started tutorial New Practice

VII. Messenger

A user-friendly logon interface should be able to record the user ID of the last logon to avoid meaningless Repeated input. To achieve this function, I will continue to process the previous login page.

1. In loginviewmodel. in CS, add a relaycommand property loadedcommand as the command object for loading the completion event on the Response view layer page, and initialize it in the constructor (pageloaded () the specific implementation of the two moveinputfocusto methods involved in the method will be detailed later ).

2. In blend 4, select "behavior" from the list on the "assets" tab, drag "eventtocommand" to [Page], and change the default name to pageloaded.

3. Bind the command attribute of pageloaded to loadedcommand (note that the eventname in the "Trigger" column in the "properties" tab should be loaded), as shown in the following two figures.

4. Assume that there is a loadlastlogininfo () method in the user class of the model that reads the user ID of the previous logon from the configuration file every time a new user object is constructed, the loginpage at the view layer determines whether the input focus should be in the user ID input box or password input box based on whether the user ID input box has a value. However, no input box can be bound to the viewmodel layer to identify the element and obtain the input focus. To do this, you must call the focus () method of the element. The problem arises: I don't want the viewmodel layer to know which interface elements need to get the input focus. To avoid the tight coupling between the view layer and the viewmodel layer, I need to use the messenger of mvvm light toolkit to remove strong references between them. First, create a new class movelogininputfocusmessage, which contains a string type attribute inputfieldname.

5. In loginviewmodel. CS, implement the two moveinputfocusto methods (message senders) involved in the pageloaded () method ).

6. In loginpage. XAML. CS, modify the loginpage constructor, register the message receiver, and provide the movelogininputfocus () method as the specific implementation.

Compiled.

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.