As posted here by Tina Tam, a “Programming-Writer” (whatever that is) on the Avalon team:

In general, setting inheritable properties is expensive in terms of
performance. If you write your own controls you should avoid defining
properties as inheritable unless you absolutely have to.

In addition, setting resources is also expensive because you are in effect
creating an inheritable property. When you replace a style in your
application, you're essentially changing a resource. For example, you might
want to change the appearance of a rectangle on your application when the
mouse pointer enters the boundary of the rectangle. To achieve optimal
performance, instead of changing the rectangle properties or resources in
the MouseEnter and MouseLeave event handlers, a better alternative is to use
a property trigger in the style for the rectangle, as in the following
example:

    <DockPanel.Resources>
      <Style>
        <Rectangle Fill="Gold" Stroke="Red" StrokeThickness="3" Width="150"
                   Height="100" Margin="10" RadiusX="10" RadiusY="10"http://www.hurlman.com/blog/file.axd?file=>
        <Style.VisualTriggers>
          <PropertyTrigger Property="IsMouseOver" Value="true">
            <Set PropertyPath="Fill" Value="limegreen"http://www.hurlman.com/blog/file.axd?file=>
          </PropertyTrigger>
        </Style.VisualTriggers>
      </Style>
    </DockPanel.Resources>
>

The above example shows the most efficient way to change the Fill property
of a rectangle when the mouse pointer enters its boundary.

It's not just a good thing to do, it's a great way to do it.  One of the best things about the Avalon structure is that all visuals can be implemented declaratively in XAML.  Just remember, true believers, if it's a visual decision, a design decision, let your designer handle it - keep it out of the code.

- G



Creative Commons License This work is licensed under a Creative Commons License.