Syaiful Nizam Yahya
Syaiful Nizam Yahya

Reputation: 4305

How to hide xaml ui element in debug

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.

Upvotes: 7

Views: 3512

Answers (2)

plinth
plinth

Reputation: 49179

There's a great article here that describes how to enable features by using an XML namespace definition. In general, it's a very low-friction approach.

Upvotes: 3

Jehof
Jehof

Reputation: 35544

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

Upvotes: 10

Related Questions