XAF Application Development tutorial (7) visual control module, xaf Application Development

Source: Internet
Author: User

XAF Application Development tutorial (7) visual control module, xaf Application Development

Most of the time, we need to display different effects according to different conditions. In traditional software development, we will directly use attributes such as the Control name. BackColor, Enable, and Visible for control.

If a business object is used in multiple places, we can either modify it in one place or control the code in a centralized way.

In XAF, a global control method is implemented.

Let's take a look at the appearance module:

Shows several effects: 1, the entire line of red background. 2. Add strikethrough to the blue font. 3. The widget is disabled when editing. 4. Cell color change.

The details page also takes effect. The above two images are web and winform.

The following shows how to make the same effect:

[Defaclasclassoptions] // [ImageName ("BO_Contact")] // [DefaultProperty ("DisplayMemberNameForLookupEditorsOfThisType")] // [defalistlistviewoptions (MasterDetailMode. listViewOnly, false, NewItemRowPosition. none)] // [Persistent ("DatabaseTableName")] // Specify more UI options using a declarative approach (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112701.aspx ). [Appearance ("Red prohibited Use "," ViewItem ", BackColor =" Red ", TargetItems =" * ", Criteria =" Disable ")] [Appearance (" blue unapproved "," ViewItem ", backColor = "Blue", TargetItems = "*", Criteria = "! Reviewed ")] public class Customer: BaseObject {

Write two Appearance attributes on the customer class.

First look at the effect:

The two simple statements have an effect. After you click to enter the detailed view, they also take effect.

Let's go to XAFML to see the appearance rules:

It seems much easier to understand than the code below, but XAF developers are used to writing rules in the code, which is faster. Otherwise, they have to switch to xafml and write code later, setting xafml later is also annoying.

So our choice is the legendary code first congestion model.

The following describes the functions of each attribute:

AppearanceItemType: Project to be controlled

  Value Description
Action Button is to be controlled
LayoutItem Name of the layout project used on the details page
ViewItem It can be simply understood as the name of an attribute. In a detailed view, in addition to the corresponding ViewItem generated by the attribute, you can also manually create viewitems such as static text and static images, of course those are under control.

Context:

Optional Value Appearance Rule's Activity Scope Example
Three built-in types of DetailView ListView Any. Detailed view, list view, or all views. Any
View ID Only valid for the specified view. MyClass_ListView; MyClass_DetailView
Any; view name View names listed after all Views except Any Any; MyClass_ListView; MyClass_LookupListView
"DetailView" or "ListView" is followed by the view name. All list views and specified views DetailView; MyClass_ListView

Criteria: takes effect when specified conditions are met, such as age> 20

Method: The rule takes effect only when the specified Method returns true. For example:

using DevExpress.ExpressApp.ConditionalAppearance;//...public class Product : BaseObject {    public Product(Session session) : base(session) { }    public decimal Price {        //...    }    public ProductStatus Status {        //...    }    [Appearance("RuleMethod", AppearanceItemType = "ViewItem", TargetItems = "*", Context = "ListView",     BackColor = "Green", FontColor = "Black")]    public bool RuleMethod() {        if (Price < 10 && Status == ProductStatus.Active) {            return true;        }        else {            return false;        }    }}

Priority: if multiple rules are applied to the same element, the Priority determines which rule will take effect. The higher the value, the higher the Priority.

TargetItems:

Example Description
"TargetElementId" target element ID For example, enter the property name, LayoutItem name
"TargetElementId1; TargetElementId2" IDs of multiple elements, separated by semicolons
"*" All elements
"*; TargetElementId1; TargetElementId2" All elements except the specified element after the * sign

BackColor: Background Color

Enable: If ViewItem is specified, LayoutItem indicates whether the control is available. If it is a button, it indicates whether it can be clicked.

FontColor: font color

FontStyle: font style, such as bold or strikethrough.

Visibility: whether it is visible.

The following table shows the effective environment:

Personalization List Cells List editing mode Detailed View

Detailed View

Static text

Layout project Layout group, TAB Button
Font Color    
Font Style    
Back Color      
Enabled/Disabled        
Visible/Invisible      

 

For example, in the list, the Visible control means that a list has many rows, so the content of some rows cannot be hidden, and the content of some rows is Visible.

 

The features of Appearance are described here.

 

QQ4603528 group: 50185791

 

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.