zoukankan      html  css  js  c++  java
  • Custom Window

    public class CustomWnd : System.Windows.Window
        {
            static CustomWnd()
            {
                DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomWnd), new FrameworkPropertyMetadata(typeof(CustomWnd)));
            }
    
            public CustomWnd()
            {
                CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, CloseWindow));
                CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, MaximizeWindow, CanResizeWindow));
                CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, MinimizeWindow));
                CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, RestoreWindow, CanResizeWindow));
            }
    
            private void CanResizeWindow(object sender, CanExecuteRoutedEventArgs e)
            {
                e.CanExecute = ResizeMode == ResizeMode.CanResize || ResizeMode == ResizeMode.CanResizeWithGrip;
            }
    
            private void RestoreWindow(object sender, ExecutedRoutedEventArgs e)
            {
                this.WindowState = System.Windows.WindowState.Normal;
            }
    
            private void MinimizeWindow(object sender, ExecutedRoutedEventArgs e)
            {
                this.WindowState = System.Windows.WindowState.Minimized;
            }
    
            private void MaximizeWindow(object sender, ExecutedRoutedEventArgs e)
            {
                this.WindowState = System.Windows.WindowState.Maximized;
            }
    
            private void CloseWindow(object sender, ExecutedRoutedEventArgs e)
            {
                this.Close();
            }
        }

    <Style TargetType="{x:Type wnd:CustomWnd}" BasedOn="{StaticResource ResourceKey={x:Type Window}}">
            <Setter Property="WindowStyle" Value="SingleBorderWindow"/>
            <Setter Property="AllowsTransparency" Value="False"/>
            <Setter Property="BorderBrush" Value="Green"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="UseLayoutRounding" Value="True"/>
            <Setter Property="WindowChrome.WindowChrome">
                <Setter.Value>
                    <WindowChrome CornerRadius="0" GlassFrameThickness="1" UseAeroCaptionButtons="False" NonClientFrameEdges="None" />
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type wnd:CustomWnd}">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid x:Name="LayoutRoot" Background="{TemplateBinding Background}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
    
                                <Grid x:Name="PART_WindowTitleGrid" Grid.Row="0" Height="30" Background="{TemplateBinding BorderBrush}">
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0">
                                        <Image Source="{TemplateBinding Icon}" Margin="0,0,5,0"/>
                                        <TextBlock Text="{TemplateBinding Title}" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center"/>
                                    </StackPanel>
    
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5,0">
                                        <Button Width="24" Height="24" IsTabStop="False" WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource SysBtnStyle}" Command="{x:Static SystemCommands.MinimizeWindowCommand}">
                                            <Button.Content>
                                                <Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,0 L10,0" Margin="0,5,0,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                            </Button.Content>
                                        </Button>
                                        <Button x:Name="PART_MAX" Width="24" Height="24" IsTabStop="False" WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource SysBtnStyle}"/>
                                        <Button Width="24" Height="24" IsTabStop="False" WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource SysCloseBtnStyle}" Command="{x:Static SystemCommands.CloseWindowCommand}">
                                            <Button.Content>
                                                <Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,0 L7.07,7.07 M0,7.07 L7.07,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                            </Button.Content>
                                        </Button>
                                    </StackPanel>
                                </Grid>
    
                                <AdornerDecorator Grid.Row="1" KeyboardNavigation.IsTabStop="False">
                                    <ContentPresenter x:Name="MainContentPresenter" KeyboardNavigation.TabNavigation="Cycle" />
                                </AdornerDecorator>
    
                                <ResizeGrip x:Name="ResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="1"
                                                IsTabStop="False" Visibility="Hidden" WindowChrome.ResizeGripDirection="BottomRight" />
                            </Grid>
                        </Border>
    
                        <ControlTemplate.Triggers>
                            <Trigger Property="WindowState" Value="Maximized">
                                <Setter TargetName="PART_MAX" Property="Command" Value="{x:Static SystemCommands.RestoreWindowCommand}"/>
                                <Setter TargetName="PART_MAX" Property="Content">
                                    <Setter.Value>
                                        <Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,3 L5,3 L5,8 L0,8Z M3,3 L3,0 L8,0 L8,5 L5,5" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            
                            <Trigger Property="WindowState" Value="Normal">
                                <Setter TargetName="PART_MAX" Property="Command" Value="{x:Static SystemCommands.MaximizeWindowCommand}"/>
                                <Setter TargetName="PART_MAX" Property="Content">
                                    <Setter.Value>
                                        <Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,0 L7.07,0 L7.07,7.07 L0,7.07Z" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            
                            <Trigger Property="IsActive" Value="False">
                                <Setter Property="BorderBrush" Value="#FF6F7785" />
                            </Trigger>
                            
                            <Trigger Property="ResizeMode" Value="NoResize">
                                <Setter TargetName="PART_MAX" Property="Visibility" Value="Collapsed" />
                            </Trigger>
    
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                                    <Condition Property="WindowState" Value="Normal" />
                                </MultiTrigger.Conditions>
                                
                                <Setter TargetName="ResizeGrip" Property="Visibility" Value="Visible" />
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
    
    
     
  • 相关阅读:
    linux常用命令的英文单词缩写
    Linux常用指令总结
    java exception "file not found or file not exist"
    Linux清空屏幕和清空当前输入的快捷键
    巨蟒python全栈开发-第10天 函数进阶
    为什么不能在函数中给全局变量赋值?
    巨蟒python全栈开发-第9天 初识函数
    巨蟒python全栈开发-第8天 文件操作
    windows10怎样关闭,开机启动项中不需要的应用?
    巨蟒python全栈开发-第7天 基本数据类型补充&深浅拷贝
  • 原文地址:https://www.cnblogs.com/RR-ghost/p/9809929.html
Copyright © 2011-2022 走看看