Windows phone7-Behaviors

Source: Internet
Author: User

Introduction

Behavior is an "action" integrated in expression blend. It facilitates the designer to add triggers and corresponding processing on the design interface without any background.CodeActually, it is a collection of code that uses a large amount of resources. It is encapsulated by MicrosoftProgramThe set is integrated into the blend; its representation is of course XAML; so that designers and developers can use it in their respective roles; the behavior-related Assembly includes: system. windows. interactivity. DLL: provides support for behavior, which defines the basic class of behavior.

Microsoft. expression. Interactions. dll: defines behavior extensions and support, including various triggers and actions

Behaviors Composition

Therefore, a behavior must have a corresponding trigger and action, and action provides us with enough space for scaling;

Learn more about behaviors:

Add behavior in conjunction with hellowp7 mvvm

1. Add a reference to Microsoft. expression. interactions.

2. Open the project in blend and find behaviors.

Move the mouse over the corresponding behavior to see the corresponding introduction...

3. behavior is found, and the rest is to add behavior in our WP7 program. This sample is very easy to add a behavior to ListBox. When the selected options change, it is displayed in the edit below;

Because we need to execute the command, drag an invokecomoandaction To The ListBox, and the blend will automatically add code for us. Then you can see the behavior in The ListBox.

The generated XAML is

 
<I: interaction. triggers> <I: eventtrigger eventname = "mouseleftbuttondown"> <I: invokecommandaction/> </I: eventtrigger>
</I: interaction. triggers>
 
4. ListBox selected processing
Add the selectcommand class and add the selectcommand attribute and select method to viewmodel. In the select method of viewmodel executed in selectcommandexcute, we assign the selected value
 
Display it to the input friend object, so that you can directly update the view.
 
Selectcommand class:
Using system; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. ink; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using hellowp7.model; namespace hellowp7.viewmodel {public class selectcommand: icommand {private readonly mainviewmodel _ viewmodel; Public selectcommand (mainviewmodel viewmodel) {_ viewmodel = viewmodel;} public bool canexecute (object parameter) {return true;} public event eventhandler canexecutechanged; Public void execute (object parameter) {If (parameter = NULL) {return;} friend Fri = parameter as friend; _ viewmodel. selected (Fri );}}}

 

Add in viewmodel:

Public icommand selectchangecommand {Get; private set ;}

 

 
Public void selected (friend) {This. Friend = friend ;}

 

Public mainviewmodel () {// initialize data _ Title = "friends book"; _ friends = new observablecollection <friend> (friendservice. getfriendsset (); _ Friend = new friend (); isnameeditable = true; refreshcommand = new refreshcommand (this); // refresh event addcommand = new addcommand (this ); selectchangecommand = new selectcommand (this );}

5. Return to blend now. Select invokecommandaction under The ListBox node and open properties on the right.

Name it selectchangeaction and set eventname to selectionchanged

Select selectechangcommand

Set the seleccommand parameter. Click advance Options => element property binding => after commandparameters and drag it to ListBox. Select selecteditem for the properyt of ListBox value.

Okay, that's all ..

After running, add a friend and select a friend in ListBox, which will help you load the information to the editor.

 

Of course, the update pull of the friend list has been implemented, because the name is the primary key in the SAVE command;

Download source code

 

 

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.