Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  

Designtime vs. Runtime


An application often looks great at runtime, but when you open it in a designer like VisualStudio or Expression Blend, the experience is quite different. The rason is that at designtime:

  • UserControls are not embedded in a parent view
    • Width and Height are not set
  • Constructor of the root-element is not called
    • Root Element is replaced by the designer
    • ViewModel is not created
  • Controls behave different
    • No mouse and keyboard events
    • Design time extensions loaded
This can be kind of annoying, especially if you want to edit data templates or layout controls.

Designtime attributes

To improve the design experience, Microsoft provides special designtime attributes that can be added to any WPF element and serve as a hint for the design tool.

The designtime attributes are defined in a special namespace, that is usually mapped to the d: prefix. To tell the XAML parser not to interprete these attributes at runtime, the markup compatibility namespace is mapped to mc: and with the mc:Ignorable="d" instruction, the d: namespace is excluded.

   xmlns:d =""
   mc:Ignorable="d" />

d:DesignHeight and d:DesignWidth

The d:DesignHeight and d:DesignWidth sets a fixed height and width for the element at designtime

    d:DesignWidth="640" d:DesignHeight="480" >
<UserControl />


If a property is set to a fixed value at runtime, but you want to override it at designtime, you can use the d:LayoutOverrides attribute. All properties that should be ignored at designtime can be listed, separated by a semicolon.

<Border Height="250" Width="160" d:LayoutOverrides="Width, Height" >

Additional Resources

MSDN Designtime-attributes

This article is still under construction

Last modified: 2011-05-04 15:22:02
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
No comments for this article

E-Mail (optional)