Community Practice for GUI developer (Project)

Source: Internet
Author: User

1: Write in multiply line when writing xaml.

2: The Code should be segmented. A piece of code can be put in different files (SRP) for one purpose ).

3: Use the correct container: if there is a gap between the button and textbox side by side, do not use a grid with three columns. Use stackpanel and the padding and magging of the space itself.

4: x: Type is recommended after DataTemplate

<DataTemplate DataType = {x: Type string}> <TextBlock Text = {Binding}> </DataTemplate> // You are advised to add the DataType attribute to identify the Type of binding, self-help.

5: The ControlTemplate must have TargetType.

<ControlTemplate TargetType = {x: Type...}>... </ControlTemplate> // you must have ContentType.

6: All Fonts definitions are implemented at a high level, or even on the windows layer.

<Window> <UserControl> Fonts definition ...... </UserControl> </Window>

 

7. differentiate ContentPresanter and ContentControls

ContentControl is the base class for every control that displays "content" (example: Label), ContentPresenter is the code used internally by ContentControl to display the content-so: 1. contentPresenter is more lightweight 2. contentPresenter is designed to be used inside control templates 3. contnetPresenter is designed to be used as-is while ContentControl is designed to be extended (custom CT)

ContentControlIs a base class for controls that contain other elements and haveContent-Property (for example,Button).

ContentPresenterIs used inside control templates to display content.

ContentControl, When used directly (it's supposed to be used as a base class), has a control template that uses ContentPresenter to display it's content.

EDIT: My rules of thumb (not applicable in every case, use your judgment ):

  1. InsideControlTemplateUseContentPresenter
  2. OutsideControlTemplate(IncludingDataTemplateAnd outside templates) try not to use any of them, if you need to, you must preferContentPresenter
  3. SubclassContentControlIf you are creating a custom "lookless" control that host content and you can't get the same result by changing an existing control's template (that shocould be extremely rare ).

ContentControl has three attributes (Content, Template, ContentTemplate), which can be designed for CT. CT can contain ContentPresenter.

Object CT DT

ContentPresenter has only two attributes (Content and ContentTemplate). It does not have the Template attribute and is used to display content within DT or CT.

Object DT

// From the class definition of contentpresenter, we can see that Class ContentPresenter {public Object Content {get; set;} public DataTemplate ContentTemplate {get; set ;}}

8: PFG2 dedicated secret, custom ContentProperty

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.