How to hide xaml ui element in debug

c#, silverlight, wpf, xaml

Solution

I´m not sure if you can do this directly in XAML by defining conditional compilation directives. But it works using the codebehind file.

First give your TextBox a name to access it in the codebehind file.

<TextBox x:Name="debugTextBox" />

and then add code to your codebehind (like the constructor)

#if DEBUG
  debugTextBox.Visibility = Visibility.Visible;
#else
  debugTextBox.Visibility = Visibility.Hidden; // or Collapsed
#endif

Problem

I create a textbox in xaml to monitor a value. this is useful when developing but i would like to hide it when running in release compile. i know i can hide the texbox by setting visibility, but i would like to automate it. thanks.

Original source