0

I wanted to create a button-Template that only reacts to the click event and is never shown in any way (i.E. no borderstyle changes on click, mouseover or something the like).
That works fine, but if I put a button with this template in a Grid, the gridpart it is in, is not clickable completly, only where the content of the button is.
How can I make my template the way its normally filling a gridpart completly?

<Style TargetType="{x:Type Button}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Name="Border">
                    <ContentPresenter RecognizesAccessKey="True"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsKeyboardFocused" Value="true">
                        <Setter TargetName="Border" Property="BorderBrush" Value="#ffffff" />
                    </Trigger>
                    <Trigger Property="IsDefaulted" Value="true">
                        <Setter TargetName="Border" Property="BorderBrush" Value="#ffffff" />
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter TargetName="Border" Property="Background" Value="Transparent" />
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter TargetName="Border" Property="Background" Value="Transparent" />
                        <Setter TargetName="Border" Property="BorderBrush" Value="#ffffff" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter TargetName="Border" Property="Background" Value="Transparent" />
                        <Setter TargetName="Border" Property="BorderBrush" Value="#ffffff" />
                        <Setter Property="Foreground" Value="Transparent"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Marcel Grüger
  • 885
  • 1
  • 9
  • 25
  • please add the code where you `put a button with this template in a Grid`. i cannot reproduce the issue, button is clickable (`Click` event fires) – ASh Apr 18 '16 at 13:48
  • Make a simple " " with a MessageBox as event. You can only click the Text. But the rest of the window remains unclickable. If you delete the template, then the whole window is one button. So the error is in the template. – Marcel Grüger Apr 18 '16 at 13:53
  • 2
    Try to set the `Background` of the `Border` to transparent. – LionAM Apr 18 '16 at 13:56
  • 1
    @MarcelGrüger, i used `Content="123"`. there is a repro now when i changed it to TextBlock. suggestion of LionAM helps. Details here: http://stackoverflow.com/questions/5344699/xnull-vs-transparent – ASh Apr 18 '16 at 14:01
  • Thanks... that it was... goddammit... so easy? Hm, thanks anyway ;) – Marcel Grüger Apr 18 '16 at 14:01

0 Answers0