Привет! Есть стиль окна. Он находится в отдельном файле. http://i.gyazo.com/318d3f5a6dac475e6e8d908425ecfe73.png
| Код | <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- Стиль главного окна --> <Style x:Key="dark-flat-main-window" TargetType="{x:Type Window}"> <Setter Property="AllowsTransparency" Value="True"/> <Setter Property="Background" Value="{x:Null}"/> <Setter Property="WindowStyle" Value="None"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Window}"> <ControlTemplate.Resources> <!-- Курсор над кнопкой управления окном --> <Storyboard x:Key="border_minimize_MouseEnter"> <!-- Анимация фона кнопки "Свернуть" (затемнение кнопки) --> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="border_minimize"> <EasingColorKeyFrame KeyTime="0" Value="Transparent"/> <EasingColorKeyFrame KeyTime="0:0:0.01" Value="#FF035C99"/> </ColorAnimationUsingKeyFrames> <!-- Анимация крестика кнопки "Свернуть" (увеличение) --> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="path_minimize"> <EasingDoubleKeyFrame KeyTime="0" Value="18"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="22"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="path_minimize"> <EasingDoubleKeyFrame KeyTime="0" Value="4"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="5"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="border_close_MouseEnter"> <!-- Анимация фона кнопки "Закрыть" (затемнение кнопки) --> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="border_close"> <EasingColorKeyFrame KeyTime="0" Value="Transparent"/> <EasingColorKeyFrame KeyTime="0:0:0.01" Value="#FF035C99"/> </ColorAnimationUsingKeyFrames> <!-- Анимация крестика кнопки "Закрыть" (увеличение) --> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="path_close"> <EasingDoubleKeyFrame KeyTime="0" Value="14"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="16"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="path_close"> <EasingDoubleKeyFrame KeyTime="0" Value="14"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="16"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="path_close"> <EasingDoubleKeyFrame KeyTime="0" Value="4"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="5"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <!-- Курсор покинул кнопку управления окном --> <Storyboard x:Key="border_minimize_MouseLeave"> <!-- Анимация фона кнопки "Свернуть" (возвращение в прежний вид) --> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="border_minimize"> <EasingColorKeyFrame KeyTime="0" Value="#FF035C99"/> <EasingColorKeyFrame KeyTime="0:0:0.01" Value="Transparent"/> </ColorAnimationUsingKeyFrames> <!-- Анимация крестика кнопки "Свернуть" (уменьшение) --> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="path_minimize"> <EasingDoubleKeyFrame KeyTime="0" Value="22"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="18"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="path_minimize"> <EasingDoubleKeyFrame KeyTime="0" Value="5"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="4"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="border_close_MouseLeave"> <!-- Анимация фона кнопки "Закрыть" (возвращение в прежний вид) --> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="border_close"> <EasingColorKeyFrame KeyTime="0" Value="#FF035C99"/> <EasingColorKeyFrame KeyTime="0:0:0.01" Value="Transparent"/> </ColorAnimationUsingKeyFrames> <!-- Анимация крестика кнопки "Закрыть" (уменьшение) --> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="path_close"> <EasingDoubleKeyFrame KeyTime="0" Value="16"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="14"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="path_close"> <EasingDoubleKeyFrame KeyTime="0" Value="16"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="14"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="path_close"> <EasingDoubleKeyFrame KeyTime="0" Value="5"/> <EasingDoubleKeyFrame KeyTime="0:0:0.01" Value="4"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources> <!-- События для кнопок "Свернуть" и "Закрыть" окно --> <ControlTemplate.Triggers> <EventTrigger SourceName="border_minimize" RoutedEvent="Mouse.MouseEnter" > <BeginStoryboard Storyboard="{StaticResource border_minimize_MouseEnter}"/> </EventTrigger> <EventTrigger SourceName="border_minimize" RoutedEvent="Mouse.MouseLeave" > <BeginStoryboard Storyboard="{StaticResource border_minimize_MouseLeave}"/> </EventTrigger> <EventTrigger SourceName="border_close" RoutedEvent="Mouse.MouseEnter" > <BeginStoryboard Storyboard="{StaticResource border_close_MouseEnter}"/> </EventTrigger> <EventTrigger SourceName="border_close" RoutedEvent="Mouse.MouseLeave" > <BeginStoryboard Storyboard="{StaticResource border_close_MouseLeave}"/> </EventTrigger> </ControlTemplate.Triggers> <Grid> <!-- Шапка окна --> <Border x:Name="header" Width="Auto" Height="30" Background="#FF017BCD" BorderThickness="0" BorderBrush="Transparent" VerticalAlignment="Top"> <Grid> <!-- Заголовок окна --> <TextBlock Width="Auto" Height="Auto" FontSize="14" Margin="9,0,0,0" Foreground="White" Text="{Binding Title,RelativeSource={RelativeSource FindAncestor,AncestorType=Window}}" HorizontalAlignment="Left" VerticalAlignment="Center"/> <!-- Кнопка "Свернуть окно" --> <Border x:Name="border_minimize" Width="30" Height="30" Background="Transparent" ToolTip="Свернуть" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,30,0" MouseLeftButtonDown="MinimizeWindow"> <Path x:Name="path_minimize" Width="18" Data="M1,1 L2,1" Stroke="White" StrokeThickness="4" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,17.431,5,8.568"/> </Border> <!-- Кнопка "Закрыть окно" --> <Border x:Name="border_close" Width="30" Height="30" Background="Transparent" ToolTip="Закрыть" HorizontalAlignment="Right" VerticalAlignment="Center" MouseLeftButtonDown="CloseWindow"> <Path x:Name="path_close" Width="14" Height="14" Data="M1,1 L2,2 M2,1 L1,2" Stroke="White" StrokeThickness="4" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </Grid> </Border> <!-- Основная часть окна --> <Border Name="body" Width="Auto" Height="Auto" Background="#FF181818" BorderThickness="0" BorderBrush="Transparent" Margin="0,30,0,80" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > <AdornerDecorator> <ContentPresenter/> </AdornerDecorator> </Border> <!-- Строка состояния --> <Border x:Name="Footer" Width="Auto" Height="80" Background="#FF017BCD" BorderThickness="0" BorderBrush="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
|
Есть главное окно для которого я применяю этот стиль:
| Код | <Window x:Class="WPF_Test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="1024" Height="768" Title="Test" WindowStartupLocation="CenterScreen" MouseLeftButtonDown="MoveWindow" Style="{DynamicResource dark-flat-main-window}">
<Window.Resources> <ResourceDictionary > <ResourceDictionary.MergedDictionaries > <ResourceDictionary Source ="Styles/Window.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources>
<Grid> ...
|
В стиле вызываются функции по свертыванию и закрытию окна (MouseButtonDoun у border). Эти функции описаны в главном окне. Но стиль ничего про это не знает. Как быть? Как связать функции в стиле с кодом в C# .cs |