Set a value to a control only in design mode

I have been working on making my project localizable. I made it using Resources just like skins but this will be another post.

The final problem I encountered was that there was no design time support to show a dummy text, in a Button for example. Everything was going well except from the design part which was not that significant for me, but as I’m the writer of the company’s new framework it might be for others.

So can you set a value to DependencyProperty of a DependencyObject only to in DesignMode?

Using a custom MarkupExtension you can. Here is the implementation

public class  DesignTimeDummy : MarkupExtension
    public DesignTimeDummy()    {

    public object  Value { get; set; }
    public override object  ProvideValue
          (IServiceProvider serviceProvider)
        if (Helpers.Designer.InDesignMode)

            return Value;

        return DependencyProperty.UnsetValue;


And this is how you can use it

<Button Style=”{DynamicResource styleName}” Content=”{CoreME:DesignTimeDummy Value=DesignContentValue}”/>


<Button Style="{DynamicResource cancelButtonStyle}" >

where CoreME is an xmlns defined namespace shortcut




  1. Pingback: ALEX TO » Blog Archive » Set a value to a control only in design mode

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s