WindowChrome - Can't click buttons in titlebar

后端 未结 2 1108
一向
一向 2021-01-15 12:42

I have a custom WindowChrome style for my WPF app (ripped from here: http://www.bdevuyst.com/wpf-custom-title-bar-and-taskbar/).

Code here:



        
相关标签:
2条回答
  • 2021-01-15 13:15

    It is your command bindings that are the issue here. Don't bind the Command properties. Simply set them:

    <Canvas Grid.Column="2" HorizontalAlignment="Right" Margin="0,6,10,0" VerticalAlignment="Top" >
        <Button x:Name="MinimizeButton"  Style="{DynamicResource Style.Button.Core.Transparent}" Command="{x:Static SystemCommands.MinimizeWindowCommand}" Width="24" Height="24" Canvas.Right="55" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close" >
            <Rectangle Margin="2" Fill="{DynamicResource appbar.reduce}" Opacity=".5" Width="15" Height="15" />
        </Button>
        <Button x:Name="NormalizeButton" Style="{DynamicResource Style.Button.Core.Transparent}" Visibility="Collapsed" Command="{x:Static SystemCommands.RestoreWindowCommand}" Width="24" Height="24" Canvas.Right="30" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Restore" >
            <Rectangle Margin="2" Fill="{DynamicResource appbar.normal}" Opacity=".5" Width="15" Height="15" />
        </Button>
        <Button x:Name="MaximizeButton" Style="{DynamicResource Style.Button.Core.Transparent}" Command="{x:Static SystemCommands.MaximizeWindowCommand}" Width="24" Height="24" Canvas.Right="30"  WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Maximize" >
            <Rectangle Margin="2" Fill="{DynamicResource appbar.maximize}" Opacity=".5" Width="15" Height="15" />
        </Button>
        <Button x:Name="CloseButton" Style="{DynamicResource Style.Button.Core.Transparent}" Command="{x:Static SystemCommands.CloseWindowCommand}" Width="24" Height="24" Canvas.Right="5" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close" >
            <Rectangle Margin="2" Fill="{DynamicResource appbar.close}" Opacity=".5" Width="15" Height="15" />
        </Button>
    </Canvas>
    

    You will also need a command binding for each of the commands and execute them programmatically as suggested by @Louis Kottmann here:

    In WPF, can I have a borderless window that has regular minimize, maximise and close buttons?

    0 讨论(0)
  • 2021-01-15 13:33

    Small addition to the correct answer. If you have something like:

    <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"
    

    And your buttons do not react to clicks - just REMOVE "shell:"

    <Button WindowChrome.IsHitTestVisibleInChrome="True"
    

    This will make them work

    0 讨论(0)
提交回复
热议问题