Title: WPF Control Template Trigger Assigned to Container
Tags: c#;wpf;xaml
Question: I've defined a control template for my top level items of a menu as follows:
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="MenuItem"&gt;
<Border x:Name="Border"&gt;
<Grid x:Name="Grid" &gt;
<ContentPresenter
ContentSource="Header"
RecognizesAccessKey="False"
Margin="10,5,50,5"
TextBlock.FontFamily="Segoe UI"
TextBlock.FontSize="14"
TextBlock.Foreground="White"/&gt;
</Grid&gt;
</Border&gt;
<ControlTemplate.Triggers&gt;
<Trigger Property="IsHighlighted" Value="true"&gt;
<Setter TargetName="Border" Property="Background" Value="{StaticResource ControlMouseOver}"/&gt;
</Trigger&gt;
</ControlTemplate.Triggers&gt;
</ControlTemplate&gt;
This is giving me the style I want, however the trigger is only triggered when I hover over the text of the menu. Ideally i want the item to become highlighted when I hover over its parent grid element. Tried changing the trigger to this
<ControlTemplate.Triggers&gt;
<Trigger Property="Grid.IsMouseOver" Value="true"&gt;
<Setter TargetName="Border" Property="Background" Value="{StaticResource ControlMouseOver}"/&gt;
</Trigger&gt;
</ControlTemplate.Triggers&gt;
but doesn't work. Any suggestions as to where I'm going wrong?

Here is the accepted answer: To make whole Border (or Grid) hit test visible you need to initialize Background property with some Brush. You can set it to Transparent for example
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="MenuItem"&gt;
<Border x:Name="Border" Background="Transparent" &gt;
<!-- --&gt;
</Border&gt;
<!-- --&gt;
</ControlTemplate&gt;


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:04/23/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><wpf><xaml>', 'Title': 'WPF Control Template Trigger Assigned to Container', 'ViewCount': 137, 'id': 29820239, 'user_AboutMe': '', 'user_AccountId': 1625727.0, 'user_DisplayName': 'James B', 'user_Reputation': 8451.0, 'user_Views': 386.0, 'user_id': 1501327.0}}