Reputation: 112
I have the following layout:
<Button VerticalAlignment="Stretch" Style="{StaticResource MyStyle} >
<TextBlock VerticalAlignment="Center">MyText</TextBlock>
</Button>
Style is defined as following:
<Style x:Key="BackButtonStyle"
TargetType="{x:Type Button}">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="GridArea"
Padding="8,4"
Margin="0,0,0,0">
<ContentControl>
<ContentPresenter x:Name="ContentPresenterArea"/>
</ContentControl>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="GridArea" Property="Background" Value="{StaticResource Some_Brush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem is that background brush changes only when mouse is over the textblock, not the entire area. I tried few things but with no effect...
Upvotes: 0
Views: 38
Reputation: 35733
GridArea
has null
Background. Elements with null
Background don't react to mouse. set Background="Transparent"
or better yet use TemplateBindings:
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="GridArea"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}"
Padding="8,4"
Margin="0,0,0,0">
Upvotes: 2