Create a style selection class:
namespace WpfApplication1 { public class DebugReleaseStylePicker { #if DEBUG internal static readonly bool debug = true; #else internal static readonly bool debug=false; #endif public Style ReleaseStyle { get; set; } public Style DebugStyle { get; set; } public Style CurrentStyle { get { return debug ? DebugStyle : ReleaseStyle; } } } }
in your App.xaml add to your Application.Resources your debug and release style + instance of StylePicker and set ReleaseStyle and DebugStyle to the previous settings styles:
<Application.Resources> <Style x:Key="WindowDebugStyle"> <Setter Property="Window.Background" Value="Red"></Setter> </Style> <Style x:Key="WindowReleaseStyle"> <Setter Property="Window.Background" Value="Blue"></Setter> </Style> <WpfApplication1:DebugReleaseStylePicker x:Key="stylePicker" ReleaseStyle="{StaticResource WindowReleaseStyle}" DebugStyle="{StaticResource WindowDebugStyle}"/> </Application.Resources>
In your window layout, set WindowStyle as follows:
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" Style="{Binding Source={StaticResource stylePicker}, Path=CurrentStyle}"> .. </Window>
You can reuse DebugReleaseStylePicker to set the style for any other control, not just the window.
Claudiu mihaila
source share