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
[ContentProperty("Value")] 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}”/>
or
<Button Style="{DynamicResource cancelButtonStyle}" > <Button.Content> <CoreME:DesignTimeDummy> Dummy </CoreME:DesignTimeDummy> </Button.Content> </Button>
where CoreME is an xmlns defined namespace shortcut
June 14, 2008 at 3:51 am
[...] 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, … [...]
June 20, 2008 at 12:28 pm
look right dog stone joke land wood land home greed right