StefanoMora-9845 avatar image
0 Votes"
StefanoMora-9845 asked StefanoMora-9845 edited

C# WPF - Button generares clicks only near the caption

Hi all,
I'm writing a C# WPF application: in the main window I have a couple of button with a custom style (border and colors).
It happens that the mouse click events are generated only near the text (the content).
I also handled other Stylus* and Preview* events but the same.

The same happens if I click using touchscreen.

Any idea?

· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What XAML elements are you using? How to reproduce the problem?

0 Votes 0 ·

It is a basic button:

  <Button x:Name="btnScala_1_43" Style="{DynamicResource ButtonRedBorder}" Content="SCALA 1/43" HorizontalAlignment="Center" VerticalAlignment="Top" Height="90" Width="600" FontSize="{DynamicResource ButtonFontSizeFerrari}" Margin="0,1298,0,0" Click="BtnScala_1_43_Click" StylusButtonUp="btnScala_1_43_StylusButtonUp" StylusDown="btnScala_1_43_StylusDown" TouchUp="btnScala_1_43_TouchUp" TouchDown="btnScala_1_43_TouchDown" StylusUp="btnScala_1_43_StylusUp" PreviewStylusButtonUp="btnScala_1_43_PreviewStylusButtonUp" PreviewTouchUp="btnScala_1_43_PreviewTouchUp" PreviewTouchDown="btnScala_1_43_PreviewTouchDown" PreviewMouseDown="btnScala_1_43_PreviewMouseDown"/>

The style is for red border and foreground color.

Strange thing: the button does not change the color following IsMouseOver and IsPressed styles.
If I press the Content everything works.

0 Votes 0 ·

The simplified button seems to work: <Button x:Name="btnScala_1_43" Content="SCALA 1/43" HorizontalAlignment="Center" VerticalAlignment="Top" Height="90" Width="600" Click="BtnScala_1_43_Click" />. The mouse click event is generated. Check if it works in your form too. Maybe the problem is caused by some issues of the other event handlers, such as btnScala_1_43_PreviewMouseDown.

0 Votes 0 ·
Show more comments

0 Answers