1

I have made a complete new style for Windows, removing the base Style to remove the base Title bar and all. This whole process works fine, close button is reimplemented and all but I have a little UX problem.

When I overrode the base style, I lost the default fade in and fade out animations on opening and closing, which I would like to get back.

I then searched for the base style used on Window thanks to a Style Snooper, but I can't find anything that would look like a Storyboard or something.

The way I overrode the base style:

<Style x:Key="WindowStyle" TargetType="Window">
    <Setter Property="Background" Value="Gray" />
</Style>

<Style x:Key="ModalWindowStyle" TargetType="Window" BasedOn="{StaticResource WindowStyle}">
    <Setter Property="WindowStyle" Value="None"/>
    <Setter Property="AllowsTransparency" Value="True"/>
    <Setter Property="SizeToContent" Value="WidthAndHeight"/>
</Style>

The Style I found through the Style snooper:

<Style TargetType="{x:Type Window}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style.Triggers>
        <Trigger Property="Window.ResizeMode">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <Border BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}">
                            <Grid>
                                <AdornerDecorator>
                                    <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
                                </AdornerDecorator>
                                <ResizeGrip IsTabStop="False" Name="WindowResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Collapsed" />
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="Window.ResizeMode" Value="{x:Static ResizeMode.CanResizeWithGrip}" />
                                    <Condition Property="Window.WindowState" Value="{x:Static WindowState.Normal}" />
                                </MultiTrigger.Conditions>
                                <Setter Property="UIElement.Visibility" TargetName="WindowResizeGrip">
                                    <Setter.Value>
                                        <x:Static Member="Visibility.Visible" />
                                    </Setter.Value>
                                </Setter>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Trigger.Value>
                <x:Static Member="ResizeMode.CanResizeWithGrip" />
            </Trigger.Value>
        </Trigger>
    </Style.Triggers>
    <Style.Resources>
        <ResourceDictionary />
    </Style.Resources>
    <Setter Property="TextElement.Foreground">
        <Setter.Value>
            <DynamicResource ResourceKey="{x:Static SystemColors.WindowTextBrushKey}" />
        </Setter.Value>
    </Setter>
    <Setter Property="Panel.Background">
        <Setter.Value>
            <DynamicResource ResourceKey="{x:Static SystemColors.WindowBrushKey}" />
        </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Window}">
                <Border BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}">
                    <AdornerDecorator>
                        <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
                    </AdornerDecorator>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

If anyone could orient me either to a way of reimplementing the exact same animation (maybe its defined somewhere and I could just use it) or to the piece of code that does that in WPF itself I would be super grateful :)

SmallRobot
  • 11
  • 2

0 Answers0