我遇到了一个问题,其中路径内容的按钮只检测鼠标点击的路径。我希望为ux在按钮的任何位置注册点击。我已将按钮的背景设置为null和透明,所以顶部控件容器指定背景样式。如何击中无效或透明背景上的检测?
下面是另一个SO后:Mouse event on transparent background
如前所述我都试过透明和空为止。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:wpfMyCustomControl">
<ControlTemplate x:Key="IconTemplate" TargetType="{x:Type ContentControl}">
<Grid>
<Path Name="ForegroundSymbol" Data="M0,0 L1,0 1,1 0,1 0.5,0.5 z" Fill="{TemplateBinding Foreground}" Stretch="Fill" />
</Grid>
</ControlTemplate>
<Style x:Key="IconButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Grid>
<ContentControl Name="icon" Template="{StaticResource IconTemplate}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="MyCustomTemplate" TargetType="{x:Type local:MyCustomControl}">
<Grid Name="LayoutRoot" Background="Red">
<RepeatButton Background="{x:Null}" Style="{StaticResource ResourceKey=IconButtonStyle}" />
</Grid>
</ControlTemplate>
<Style TargetType="{x:Type local:MyCustomControl}">
<Setter Property="Template" Value="{StaticResource ResourceKey=MyCustomTemplate}" />
</Style>
</ResourceDictionary>
如果我从“样式”中删除“x:Key”属性,控件呈现。我已经能够重现这个问题,使用上面的xaml控件样式,点击检测不会在按钮的“背景”部分触发。
如果你提供了一些代码给我们看,会有很大的帮助。 – JerKimball 2013-03-02 00:51:55
'iconstyle'如何?任何问题都可能与控制模板的“VisualTree”一致。 – JerKimball 2013-03-02 02:56:12
我无法用按钮,您的''和按钮的{{:Null}'背景来重现此操作。这证明这是你造成这种情况的'Style'。开始解构风格,直到问题消失,或者以其他方式开始:从空白样式开始,添加东西,直到问题出现。无论哪种方式,你会发现究竟是什么导致问题,并反过来将使您能够解决问题。 –
2013-03-04 07:12:58