6

I am using design time namespace to use design time properties and elements. I use

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

Now, I need to define design time element, let's say

<d:TextBlock Text="design time text block" />

But in runtime, I want to display other text block:

<TextBlock Text="runtime text block" />

How to define both elements, so design time elemnt is displayed instead of respective run time element?

The way I fiugred out is:

<Grid>
    <d:TextBlock Text="design time text block" />
    <TextBlock Text="runtime text block" />
</Grid>

But I don't want to define extra container. I could also use <d:Grid>`, but it justs omits whole grid together with text block in runtime.

I know I can use d:Text design time property, but in real situation I need to set attached property on element, whcih already has its own namespace, eg. ns:AttachedProp and I cannot use two namespaces like d:ns:AttachedProp.

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
  • @MickyD I see what you mean, but the control itself is custom button control, so it would not work. – Michał Turczyn Nov 24 '20 at 09:48
  • ah I see. No problem good sir –  Nov 24 '20 at 09:51
  • I wasn't aware you can use design-only elements. But you can easily [check for design mode](https://stackoverflow.com/q/834283/1997232) in logic of attached behavior or somewhere else. – Sinatr Nov 24 '20 at 10:35
  • Are you wanting design time controls rather than design time data? I'm not sure what that gains you over design time data and databinding. – ChrisBD Dec 04 '20 at 12:21
  • 1
    Something like that? Or is it more complicated? – Klamsi Dec 04 '20 at 12:23
  • Perhaps, you need not attribute-property, but element-property? – JohnyL Dec 04 '20 at 15:21
  • I have always used `d:DataContext="{d:DesignInstance vm:ViewModel}"` to deal with these instances. However I don't know how this works with attached props. There is also a way for you to generate this data based on vm through Blend. – XAMlMAX Dec 08 '20 at 11:56

0 Answers0