gpt4 book ai didi

c# - WindowChrome - 无法单击标题栏中的按钮

转载 作者:行者123 更新时间:2023-11-30 21:43:13 57 4
gpt4 key购买 nike

我的 WPF 应用程序有一个自定义 WindowChrome 样式(从这里获取:http://www.bdevuyst.com/wpf-custom-title-bar-and-taskbar/)。

代码在这里:

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">

<!-- Simple style without anything to remove the title bar -->
<Style x:Key="Style.Window.WindowStyleNoneWithTaskbar.Base" TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome" >
<Setter.Value>
<shell:WindowChrome GlassFrameThickness="0" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Foreground}" BorderThickness="1" >
<ContentPresenter Content="{TemplateBinding Content}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- Simple style with system buttons upper right -->
<Style TargetType="{x:Type Window}" BasedOn="{StaticResource Style.Window.WindowStyleNoneWithTaskbar.Base}" x:Key="Style.Window.WindowStyleNoneWithTaskbar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Foreground}" BorderThickness="1">
<Grid>
<ContentPresenter
Content="{TemplateBinding Content}" />

<Canvas Grid.Column="2" HorizontalAlignment="Right" Margin="0,6,10,0" VerticalAlignment="Top" >
<Button x:Name="MinimizeButton" Style="{DynamicResource Style.Button.Core.Transparent}" Command="{Binding Source={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="{Binding Source={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="{Binding Source={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="{Binding Source={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>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="WindowState" Value="Maximized">
<Setter Property="Visibility" Value="Collapsed" TargetName="MaximizeButton" />
<Setter Property="Visibility" Value="Visible" TargetName="NormalizeButton" />
</Trigger>

</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

我删除了对“shell:”的引用,因为它已被弃用,但出于某种原因,我无法单击标题栏中的按钮。我从我链接的网站下载了示例解决方案,按钮对我有效。

接下来,我添加了对“shell”的引用,但我仍然无法点击按钮。

我不确定我在这里做错了什么。我几乎完全将示例解决方案复制到我的项目中,但它仍然 不起作用。我将每个按钮的 IsHitTestVisibleInChrome 设置为“true”,但这没有什么不同。

我尝试了其他几种更简单的方法,使用基本按钮且没有样式,但都无济于事。我觉得我在这里遗漏了一些明显的东西。

最佳答案

对正确答案的小补充。如果你有类似的东西:

<Button shell:WindowChrome.IsHitTestVisibleInChrome="True"

并且您的按钮不会对点击使用react - 只需删除“shell:”

<Button WindowChrome.IsHitTestVisibleInChrome="True"

这会让他们工作

关于c# - WindowChrome - 无法单击标题栏中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41905412/

57 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com