其他分享
首页 > 其他分享> > 使用WindowChrome 在切换ResizeMode值时的问题

使用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;
        }
    }
}

 

标签:值时,ResizeMode,Windows,标题栏,System,WindowChrome,using,MainWindow
来源: https://www.cnblogs.com/maoyuanwai/p/12260270.html