zoukankan      html  css  js  c++  java
  • wpf 自定义窗体 另一种实现方式

    最初接触wpf时候做自定义的窗体 用来改变标题栏样式并支持拖动缩放,适用的事两个window 那种方式,网上有好多例子,但是后来觉得太麻烦了(每次都是以太麻烦为动力=。。=)

    于是 找到了第二种方式 windowchrome

    windowchrome 位于microsoft.windows.shell dll中是一个开源的库。

    它的原理就是在窗体外面覆盖一层控件 其实和两个窗体的方案差不多。

    上图:

    image

    其中主要要注意的有两点:

    第一是 由于覆盖的问题会导致标题栏的按钮无法命中,可能导致选中或者触发不正确的问题,所以需要如下设置

    <Button  shell:WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource CloseButtonStyle}"
                               HorizontalAlignment="Right" Margin="0,0,25,0" Width="24" Height="24"
                           Command="{x:Static shell:SystemCommands.CloseWindowCommand}"
                        CommandParameter="{Binding ElementName=SelectDialog}">
                </Button>

    第二 windowchrome 默认提供了几个命令 如最大化 最小化 关闭等 可以绑定。

    <Window.CommandBindings>
            <CommandBinding Command="{x:Static shell:SystemCommands.CloseWindowCommand}"
                        Executed="_OnSystemCommandCloseWindow"/>
        </Window.CommandBindings>
    
    
      private void _OnSystemCommandCloseWindow(object sender, ExecutedRoutedEventArgs e)
            {
                SystemCommands.CloseWindow((Window)e.Parameter);
            }

    大笑 就到这里了

  • 相关阅读:
    [From 11.1~11.4]事件
    [From 10.1~10.5] 对象和集合初始化器(C#语法糖系列)
    [From 9.3]out和ref关键字
    [From 8.5]转换操作符方法
    将博客搬至CSDN
    QPS 与 TPS 简介
    在cenos中,通过subversion源码进行安装
    no acceptable C compiler found in $PATH
    tgz解压
    程序中的@Override是什么意思?
  • 原文地址:https://www.cnblogs.com/aoldman/p/2881635.html
Copyright © 2011-2022 走看看