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

STY$002Checked automatically with code checker

Synopsis:Consider introducing implicit styles to avoid duplication of XAML code
Severity Level:1


Sometimes, your XAML needs to define a number of elements of the same type that should all have certain properties set in the same way. In order to avoid duplication of XAML code, you should consider defining a local implicit style to take care of all the commonalities. Implicit styles are one of the most powerful tools that the XAML developer has to increase the uniformity of the UI elements, and to enhance the readability and the maintainability of the XAML code.

The following example illustrates the use of an implicit style based on an existing custom button style that sets the width and height for a collection of buttons.

  <!-- If you do not define an implicit style, each of the properties must be set 
     explicitly for each button, even if, by design, a property should have the
     same value for multiple buttons. -->
<Button x:Name="okButton"
    Width="120" Height="38"/>
<Button x:Name="cancelButton"
    Width="120" Height="38"/>

  <!-- Define an implicit style.
     Note that an implicit style should not have an x:Key. -->
    BasedOn="{StaticResource MyCustomButtonStyle}"
    TargetType="{x:Type Button}">
    <Setter Property="Width" Value="120"/>
    <Setter Property="Height" Value="38"/>
<!-- The implicit style will be applied to these buttons without explicitly
     setting it. This means that the OK and the Cancel button will both have
     the width and the height that is specified by the implicit style. -->
<Button x:Name="okButton"
<Button x:Name="cancelButton"