2

I have a need to display a certain WPF control only in the [VS 2017] designer, but not during run time. (Specifically, a background image to lay out the components).

As I learned, the opposite effect (hiding a control at design time) can be achieved using the undocumented d:IsHidden="true" attribute, from the namespaces that are typically included even by default:

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
mc:Ignorable="d"

There is another feature to have a design-time style with d:DesignStyle.

But I couldn't find anything like d:Visible or something to the effect.

So, are there any simple methods to have a design-time-only component, similar to having a special 'd' attribute? I'd prefer not to use a custom code-behind, because there is at least a trivial (but annoying) solution: just comment out the component before compilation!

Ideally, the whole component should be disabled/removed at run time, so that it didn't take any resources.

More generally, is there a way to find all these 'undocumented' features of the d namespace?

Lennart
  • 9,657
  • 16
  • 68
  • 84
Zeus
  • 1,052
  • 1
  • 9
  • 18

2 Answers2

2

You could just put this in your Window or UserControl constructor after the InitializeComponent() call:

if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) 
{
    myDesignControl.Visibility = Visibility.Collapsed;
}

Doing this also allows the ability to turn the control back on again at runtime, which I often find useful for debugging tools or diagnostics.

Jeff R.
  • 1,493
  • 1
  • 10
  • 14
  • That's what I'll have to do, in the end, until someone discovers a documentation for that Blend namespace, and there is something more useful in it... – Zeus Sep 03 '18 at 05:41
1

'd' is not magical nor anything official. It is an alias for an xml namespace that is local to to xaml/XML file where it is defined.

This line defines d in the code in the question:

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

So to find information about 'features' of this namespace there should be a list of all classes that are in this namespace. Most of them are in the Microsoft Expression Blend SDK: https://www.microsoft.com/en-us/download/details.aspx?id=22829

Emond
  • 50,210
  • 11
  • 84
  • 115
  • I have this SDK. But I couldn't find _any_ documentation on this namespace. By doing global search on the known keywords, I found that it belongs to `Microsoft.Expression.Prototyping.SketchControls.design.v4.dll`, but no other trace anywhere else... It's a pity, because all the things I know (and mentioned) about it so far can be extremely useful. – Zeus Aug 30 '18 at 05:57