I have some useful wpf buttons to test some functionality. It would be good not to show them in release but in debug indeed.
Doing it from code is easy. But I'd prefer a declarative solution.
The only solution I know of is to create a static property somewhere like this:
public static Visibility IsDebug { #if DEBUG get { return Visibility.Visible; } #else get { return Visibility.Collapsed; } #endif }
Then use it in XAML like this:
<MyControl Visibility="{x:Static local:MyType.IsDebug}" />
XAML doesn't have anything for compiler flags.
This will show when the debugger is attached. First, set the namespace:
xmlns:diag="clr-namespace:System.Diagnostics;assembly=mscorlib"
then set your resource:
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
then use the binding:
<MenuItem Header="onlyIfDebuggerAttached" Visibility="{Binding Source={x:Static diag:Debugger.IsAttached}, Converter={StaticResource BoolToVisibilityConverter}}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With