Wednesday, October 31, 2012

How to hide xaml ui element in debug

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.

Answers & Comments...

Answer: 1

I´m not sure if you can do this directly in XAML by defining conditional compilation directives. But it should work 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 

No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog