Mgen spa Engineering 2 tutorial (Part 1): Use the dynamic initialization control and iviewawarespaclass Interface

Source: Internet
Author: User

Back to the tutorial directory

Note: This articleArticleThe minimum requirement is 2.3 in the spa project.

 

In spa Engineering 2 tutorial (Part 1): List controls, we talked about pre-defined list control operations in spa engineering. Whether it is a single-choice or multiple-choice list control, the data source of the control is usually set in two ways: one is a string array, the other is the enumeration type (the multi-choice mode is implemented using the flags enumeration ). If you want to implement dynamic initialization controls, you can select Custom Controls (refer to: spa Engineering 2 tutorial (Part 1): custom controls), but after spa Project 12th, added a commonly used dynamic initialization list control: selectorobjectcontrol.

 

We will take the SPA project 2.3Source codeExamples inProgramThe interface generation type is myspagrouptype, Which is nested with another type: myspatype. In the child type myspatype, we define the attributes of the selectorobjectcontrol control. The name is path:

[Spaheader("Objectsel")]

[Selectorobjectcontrol(Selectortype.ListBox)]

Public ObjectPath {Get;Private Set;}

Note that the definition of the selectorobjectcontrol is different from that of other selector controls. Because the selectorobjectcontrol is dynamically initialized, you do not need to define the data source during declaration. At the same time, we can see from the name that the data type of this control is object.

 

Next, we should initialize the control. Therefore, we have to mention the iviewawarespaclass interface added to spa project 2.3, which is located in mgen. spa. in the UI namespace, it is defined as follows:

NamespaceMgen.SPA.UI

{

Public Interface Iviewawarespaclass

{

VoidInitialupdated ();

VoidUiclosed (SpauieventargsE );

VoidUiloaded (SpauieventargsE );

}

}

 

The readers of these three members should be familiar with it. These three members correspond to three events in the ivalidationcontroller interface:

This interface is used as follows: when the SPA project generation type in the outermost layer executes this interface (that is, it is useless to execute the attribute type modified by spagroupheader ), after an ivalidationcontroller event occurs, the iviewawarespaclass interface method will also be called.

Readers may wonder why iviewawarespaclass is needed to get ivalidationcontroller through spaobject?

The difference is that the validationcontrol attribute of the spaobject can only be obtained at the execution time. With the iviewawarespaclass interface, the type definition time can also have corresponding actions when the corresponding event occurs. The biggest benefit of doing so is that we can add dynamic content when defining the type.CodeTo complete the topic we are discussing today: "Use of dynamic initialization controls ".

 

These three events are part of the last part of the Tutorial: spa Engineering 2 tutorial (Part 1): I have explained how to use ivalidationcontroller to query the status and access the UI control, so I don't need to talk about them here. We can use the spauieventargs type in the parameter to obtain the Update Status and directly access the UI control.

First, let's execute the iviewawarespaclass interface for the SPA project generation type myspagrouptype at the outermost layer:

Class Myspagrouptype:Iviewawarespaclass

 

Then execute the corresponding method. In the uiloaded method, we can initialize the control. Note that the attributes of the selectorobjectcontrol control are defined in the nested type myspatype, therefore, when getting the UI control through spauieventargs, You need to input two paths. After obtaining the UI control, you can set the internal selector control (System in WPF and WP8. windows. controls. primitives. selector type. Windows is used in winrt. XAML. UI. controls. primitives. selector type.

 

Therefore, the myspagrouptype uiloaded method is defined as follows (we use the current time as the data source for testing ):

Public VoidUiloaded (SpauieventargsE)

{

// Return the interface control through the path

VaRSelector=(Selector) E.Getui (New[] {"Group","Objectsel"});

// Set the selector Data Source

Selector.Itemssource= New Datetime[]

{

Datetime.Now,

Datetime.Now.Addyears (5),

Datetime.Now.Addyears (-5)

};

}

 

Running result:

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.