XAF Application Development Tutorial (vii) Appearance control module

Source: Internet
Author: User

Many times, we need to show different effects according to different conditions, in traditional software development, we will directly use the name of the control. Backcolor,enable,visible, and other attributes are controlled.

If a business object is used in multiple places, either we will go to a place where a change is made, or the code will be centralized to do a method of control.

In Xaf, a method of controlling global effectiveness is implemented.

Let's take a look at the façade module:

Several effects are shown: 1, the entire line of red background. 2, blue font plus strikethrough. 3 edit-time control is disabled. 4. Cell color change.

In the detailed interface, the same takes effect, above two pictures, one is web, one WinForm.

Below we show how to make the same effect:

[Defaultclassoptions]//[ImageName ("Bo_contact")]//[Defaultproperty ("Displaymembernameforlookupeditorsofthistype")]//[Defaultlistviewoptions (Masterdetailmode.listviewonly, False, Newitemrowposition.none)]//[Persistent ("Databasetablename")]//specify more UI options using a declarative approach (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112701.aspx).[Appearance ("Red Disabled","ViewItem", BackColor ="Red", Targetitems ="*", Criteria ="Disabled")] [Appearance ("Blue not approved","ViewItem", BackColor ="Blue", Targetitems ="*", Criteria ="! Audited")]     Public classclient: baseobject {

Write two appearance attribute on the customer class.

First look at the effect:

A very simple two statement has the effect, click into the Detailed view, it is also effective.

Let's go to Xafml and look at the appearance rules:

It looks much easier to understand than the code below, but the XAF developers are accustomed to writing rules in code, which is faster, or switching to XAFML, writing code, and setting up Xafml is annoying enough.

So our choice is the legendary code first congestion model.

Here's a look at the functionality of each of the properties:

Appearanceitemtype: Items to control

Value description
Action To control is the button
Layoutitem The name of the layout item used in the detailed interface
ViewItem Can be simply understood as the name of the property, in the detailed view in addition to the property will generate corresponding ViewItem, but also can be manually set up such as static text, static image class ViewItem, of course those are also within the control range.

Context:

Optional Values appearance Rule ' s Activity Scope Example
Built-in three types of DetailView ListView any. Detailed view, List view, or all views. Any
The specified view ID Only takes effect on the specified view. Myclass_listview; Myclass_detailview
Any; view name All views, except for the view names listed after any any; Myclass_listview; Myclass_lookuplistview
"DetailView" or "ListView" followed by the view name. All list views, and the specified view DetailView; Myclass_listview

Criteria: Effective When the specified conditions are met, such as age >20

Method: The rule will not take effect until the specified method returns a true value, such as:

usingDevExpress.ExpressApp.ConditionalAppearance;//... Public classProduct:baseobject { PublicProduct (Session session):Base(session) {} Public decimalPrice {//...    }     Publicproductstatus Status {//...} [Appearance ("Rulemethod", Appearanceitemtype ="ViewItem", Targetitems ="*", Context ="ListView", BackColor="Green", FontColor ="Black")]     Public BOOLRulemethod () {if(Price <Ten&& Status = =productstatus.active) {return true; }        Else {            return false; }    }}

Priority: If more than one rule is applied to the same element, it will be determined by that priority which will take effect and the higher the value the greater the precedence.

Targetitems:

Example Description
"Targetelementid" target element ID For example, fill in the name of the property, Layoutitem name
"TARGETELEMENTID1; TargetElementId2 " IDs of multiple elements, separated by semicolons
"*" All elements
"*; TARGETELEMENTID1; TargetElementId2 " All elements, except for the specified element following the * number

BackColor: Background color

Enable: If the specified Viewitem,layoutitem is an allegation that the item is available. If it is a button, it refers to whether it can be clicked.

FontColor: Font Color

FontStyle: Font styles, such as bold, strikethrough, and so on.

Visibility: Is visible.

The following table shows the environments in effect:

Personalization List Cells List Edit mode Detailed View

Detailed View

static text

Layout Items Layout group, TAB Button
Font Color
Font Style
Back Color
Enabled/disabled
Visible/invisible

For example, in the list, visible control, a list has a lot of rows so there must be no way to do some of the contents of the line is hidden, some of the contents of the line is visible.

Appearance's function is described here.

QQ4603528 Group: 50185791

XAF Application Development Tutorial (vii) Appearance control module

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.