ResourceDictionary и events

207
08 февраля 2019, 22:00

Вопрос таков. Создал я стиль для окна, закинул его в словарь ресурсов, что бы использовать не на одной форме, но могу ли я реализовать события, которые присутствуют в стиле? Или "стиль" на то и "стиль", что он только для визуальной части предназначен? Тогда посоветуйте как можно описать события "WinMove" и "CloseApp"? Словарь:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:WpfApp123"
                    x:Class="WpfApp123">

    <Style x:Key="pekus" TargetType="{x:Type Window}">
        <Setter Property="WindowStyle" Value="None"/>
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome 
                        CaptionHeight="0"/>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border >
                        <Grid Background="#62929E">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="28"></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <!-- Header -->
                            <Border Grid.Row="0" Background="#4A6D7C" >
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="20*"></ColumnDefinition>
                                        <ColumnDefinition></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <Grid Grid.Column="0">
                                        <TextBlock Name="txtTitle" Text="Test" FontSize="18" TextAlignment="Center"
                                                   Foreground="White" MouseLeftButtonDown="WinMove"/>
                                    </Grid>
                                    <Grid Grid.Column="1">
                                        <Button Name="btnTitleClose" HorizontalAlignment="Right"
                                            Width="30" Click="CloseApp" 
                                                    Background="Transparent" BorderBrush="Transparent">
                                            <Image Source="img.png">
                                            </Image>
                                        </Button>
                                    </Grid>
                                </Grid>
                            </Border>
                            <!--- end header-->
                            <!-- Body -->
                            <Border Grid.Row="1">
                                <AdornerDecorator>
                                    <ContentPresenter/>
                                </AdornerDecorator>
                            </Border>
                            <!-- end body -->
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
READ ALSO
ASP .NET Core сервер с UDP клиентами

ASP .NET Core сервер с UDP клиентами

Есть ASPNET Core сервер, в котором есть некоторый REST api

198
2 консоли в одном проекте C# .NET

2 консоли в одном проекте C# .NET

Хай, у меня есть проект в котором есть класс сервера и класс клиентаХотелось бы реализовать следующее: При запуске проекта запускается первая...

219