zoukankan      html  css  js  c++  java
  • 使用WindowChrome 在切换ResizeMode值时的问题

    使用WindowChrome 在切换ResizeMode值时的问题,比如从NoResize切换到CanResize后,此时点击标题栏,标题栏的默认按钮(最小化、最大化、关闭按钮)会显示出来

    如图:

     测试代码:

    <Window x:Class="WindowChromeTest.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
            xmlns:local="clr-namespace:WindowChromeTest"
            ResizeMode="CanMinimize"
            WindowStyle="None"
            mc:Ignorable="d"
            Title="MainWindow" Height="188" Width="326">
        <Window.Resources>
            <Style TargetType="local:MainWindow">
                <Setter Property="shell:WindowChrome.WindowChrome">
                    <Setter.Value>
                        <shell:WindowChrome
                            CaptionHeight="50"
                            GlassFrameThickness="0"
                            CornerRadius="0"
                            ResizeBorderThickness="2"
                            ></shell:WindowChrome>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type local:MainWindow}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="50"></RowDefinition>
                                    <RowDefinition Height="*"></RowDefinition>
                                </Grid.RowDefinitions>
                                <Border Grid.Row="0" Background="Orange">
                                    <StackPanel Orientation="Horizontal">
                                        <Button shell:WindowChrome.IsHitTestVisibleInChrome="True" Content="Test Button" Click="Button_Click"></Button>
                                    </StackPanel>
                                </Border>
                                <Border Grid.Row="1" Background="White">
                                    <ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <TextBlock>
            设置此值可解决问题:
            WindowStyle="None"
        </TextBlock>
    </Window>
    using Microsoft.Windows.Shell;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WindowChromeTest
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                Application.Current.MainWindow.ResizeMode = ResizeMode.CanResize;
            }
        }
    }
  • 相关阅读:
    《代码整洁之道》
    SharePoint Use backup, restore and export
    sharepoint站点支持AJAX功能做些简要说明
    使用vbs或者bat脚本修改IE浏览器安全级别和选项
    创建 Silverlight 应用程序以访问 SharePoint 2010 数据
    CPU使用率过高的 9种可能
    几条在SharePoint中使用SilverLight注意事项
    通过WebService操作SharePoint列表数据
    开发部署Sharepoint自定义webservice
    SQL Server发送邮件的存储过程
  • 原文地址:https://www.cnblogs.com/maoyuanwai/p/12260270.html
Copyright © 2011-2022 走看看