TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
XAML Coding Standard
Search

ORG$005Checked automatically with code checker

Synopsis:Organize properties in the right order
Language:XAML
Severity Level:1
Category:Organization and Layout


Description:

Consider organizing the properties as follows:

  1. XAML element type and x:Name;
  2. The Style property;
  3. Attached properties, such as Grid.Row, Grid.Column, or DockPanel.Dock;
  4. Properties related to the content of the UI element, such as Content, ToolTip, or Text;
  5. Properties related to the layout of the UI element, such as Width, Height, Margin, HorizontalAlignment, VerticalAlignment, Stretch, etc.;
  6. Properties related to the visibility of the UI element, such as Visibility and Opacity.

The following example illustrates these organization principles. In this example, we define a custom button that is put in the second row and third column of a grid (note that grids use zero-based indexing of their rows and columns). Furthermore, the custom button has custom content and a custom tooltip, and has several layout properties set. We apply the previous recommendation of putting related properties on the same line. The custom button is intended not to be visible by default - a trigger (not shown here) will take care of making the button visible under the right conditions.

  <Button x:Name="myCustomButton"
    Style="{DynamicResource MyCustomButtonStyle}"
    Grid.Row="1" Grid.Column="2"
    Content="My custom button content"
    ToolTip="My custom button tooltip"
    Width="120" Height="38"
    HorizontalAlignment="Center" VerticalAlignment="Center"
    Margin="6,0"
    Visibility="Hidden"/>