I'm running into a problem where a button with path content is only detecting mouse clicks on the path. I'd like to, for ux, to have the click registered anywhere in the button. I've set the background of the button to both null and transparent so the top control container dictates the background style.
Here's another SO post : Mouse event on transparent background
As stated I've tried both transparent and null so far.
<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>
If I remove the "x:Key" attribute from "Style", the control renders. I've been able to reproduce the issue, with the above xaml control style, where the hit detection does not trigger on the "background" portion of the button.
iconstyle
? Any issues are most likely going to be with theVisualTree
of the control template. – JerKimball<Path>
and a{x:Null}
background for the button. This proves it's yourStyle
that's causing this. Start deconstructing the Style until the problem goes away, or start the other way around: Start with a blank style and add stuff until your problem shows up. Either way you'll find exactly what's causing the problem and that in turn will enable you to solve the problem. – Cosmin Prund