I have two different styles for my window:
The window is too wide for either of the monitors on my development machine, but it's a perfect fit for the target/install machine. So, when debugging, I need to be able to move the Window so I can see everything on it, but when I release the app, I need it to run in "full screen" mode (like a PowerPoint app in projector mode).
Is there any way to set the Style
property of the window based on whether I'm compiling in Debug vs. Release mode? I was thinking I might be able to use a binding, but I'm not quite sure how to implement it.
Create a Style picker 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 + a instance of the StylePicker and set the ReleaseStyle and DebugStyle to the previous set up 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 markup set up the WindowStyle like this:
<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 the DebugReleaseStylePicker to set the style to any other control not just the Window.
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