I have a modal dialog I am displaying using the WPF Extended Toolkit's ChildWindow
but I don't like the default look of the window since it doesn't support System Colors correctly (it has a forced white background) and doesn't adapt to the Windows Classic Shell when being used.
I am therefore trying to create my own style for the
ChildWindow
but in doing so I've broken the dialog behaviour of the control - how would I style it to get this behaviour back?
My style for the dialog is as follows.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfToolkit="http://schemas.xceed.com/wpf/xaml/toolkit">
<Style TargetType="wpfToolkit:ChildWindow">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="wpfToolkit:ChildWindow">
<!--<Window WindowState="{TemplateBinding WindowState}" Visibility="{TemplateBinding Visibility}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}">-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.RowSpan="2"
BorderThickness="2"
BorderBrush="Gold"/>
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Lime"/>
<GradientStop Color="DarkGreen"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Foreground="White" Text="{TemplateBinding Caption}"/>
<ContentPresenter Grid.Row="1"/>
</Grid>
<!--</Window>-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
I have tried nesting it in a window to get the dialog behaviour back but instead I get a runtime exception of "Window must be the root of the tree. Cannot add Window as a child of Visual.". What do I need in my style?
Start with the default style and customize it to your needs:
XAML: