gpt4 book ai didi

wpf - 图像按钮仅在单击图像而不是按钮内部区域时响应

转载 作者:行者123 更新时间:2023-12-03 13:52:49 25 4
gpt4 key购买 nike

我正在使用以下按钮样式,它去掉了边框并制作了透明背景来制作我的图像按钮:

  <Style x:Key="EmptyButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="#00000000"/>
<Setter Property="BorderBrush" Value="#00000000"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

样式来自以下答案:
WPF button with image of a circle

现在的问题是,无论实际按钮有多大,可点击区域都仅限于图像:

Button problem

我的按钮代码:
<Button Name="n02" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Style="{DynamicResource EmptyButtonStyle}" Canvas.Left="308" Canvas.Top="157" Height="106" Width="120">
<Image Source="boto_face_off.PNG" Height="61" Width="59" />
</Button>

问题:如何使整个按钮区域对点击使用react?我想像现在一样保持透明且没有边界。

最佳答案

您可以将演示者包裹在 Border 中有界Background .

<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<!-- ContentPresenter here -->
</Border>
</ControlTemplate>

样式集 Background到一些透明的东西,但它甚至从未在 Template 中使用过,这样 Border将使整个区域的 HitTest 。

关于wpf - 图像按钮仅在单击图像而不是按钮内部区域时响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7541858/

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