Search code examples
c#xamlvisual-studio-2012preview

Show outline of empty label in Visual Studio


I am working on a XAML page in VS2012.

The page has a couple of empty labels (which programatically get filled in later). Because the labels are empty, they do not appear on the page unless moused over.

Is there any way to have VS show me the outline of these labels only in the design pane (so in release it would be invisible).


Solution

  • First and foremost, the comments are correct - you should fill the controls in with dummy values and then clear them on startup (either automatically with databinding, or otherwise).

    Now, to actually answer the question, you can check if Visual Studio is in "Design Mode", and then programmatically set the border of a control... or better, set the text to something easily noticeable in the UI:

    // Check for design mode. 
    if ((bool)(DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)) 
    {
        myTextBlock.Text = "*** DESIGN ***";
    }
    

    This code should be run in the constructor of your WPF window/control class (or something invoked from the constructor) so that the designer executes it.

    The code to check for design time was taken from this post.