窗口标题栏中的按钮

时间:2016-03-30 15:51:28

标签: c# wpf

我正在尝试实现自定义窗口镶边。我正在使用Miscrosoft.Windows.Shell命名空间。当我在标题栏上放置按钮时,它对事件是透明的。默认按钮应该有浅蓝色背景,当我将鼠标悬停在它上面时,它没有这种效果。另一个不在标题栏内的按钮可以正常触发事件。Custom window

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
    Title="MainWindow" Height="600" Width="800" Background="#2D2D30" Name="MyWindow"
    WindowStartupLocation="CenterScreen" AllowsTransparency="True" WindowStyle="None">
<Window.Style>
    <Style TargetType="Window">
        <Setter Property="shell:WindowChrome.WindowChrome">
            <Setter.Value>
                <shell:WindowChrome CaptionHeight="25" GlassFrameThickness="0"
                        CornerRadius="0" ResizeBorderThickness="7"/>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="WindowState" Value="Maximized">
                <Setter Property="shell:WindowChrome.WindowChrome">
                    <Setter.Value>
                        <shell:WindowChrome CaptionHeight="32" GlassFrameThickness="0"
                        CornerRadius="0" ResizeBorderThickness="7"/>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Style>
<Grid>
    <Grid.Style>
        <Style TargetType="Grid">
            <Setter Property="Margin" Value="7,0,7,7"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=MyWindow, Path=WindowState}" Value="Maximized">
                    <Setter Property="Margin" Value="7,7,7,7"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Grid.Style>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <DockPanel LastChildFill="False" Grid.Row="0" Height="32">
        <Button DockPanel.Dock="Right" Width="32" Height="32"/>
    </DockPanel>
    <Border Background="#1E1E1E" Grid.Row="1">
        <Button Width="100" Height="100"/>
    </Border>
</Grid>

1 个答案:

答案 0 :(得分:0)

你应该添加附加属性“shell:WindowChrome.IsHitTestVisibleInChrome”= true,这应该可以解决你的错误。