Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 657
Syaiful Nizam Yahya Avatar asked Oct 31 '12 10:10

Syaiful Nizam Yahya


1 Answers

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
like image 180
Jehof Avatar answered Sep 26 '22 17:09

Jehof