.NET Programming
--
Questions
--
Followers
Top Experts
MenuItem Style on mouseover - WPF
Hi,
I'm trying to change the styling of when someone mouseover a menuItem (in xaml)
I tried to add a parent "MenuItem.Style" to the "Style" element, but it apparently doesnt exist.
Any Ideas?
I'm trying to change the styling of when someone mouseover a menuItem (in xaml)
<Menu Height="30" HorizontalAlignment="Center" Name="MenuTools" VerticalAlignment="Center" Width="360" Background="{x:Null}">
<MenuItem Name="New">
<MenuItem.Icon>
<Image Source="/Chalkboard_wpf;component/Resources/new.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="Save">
<MenuItem.Icon>
<Image Source="/Chalkboard_wpf;component/Resources/save.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="Open">
<MenuItem.Icon>
<Image Source="/Chalkboard_wpf;component/Resources/open.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="Cut">
<MenuItem.Icon>
<Image Source="/Chalkboard_wpf;component/Resources/cut.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="Paste">
<MenuItem.Icon>
<Image Source="/Chalkboard_wpf;component/Resources/paste.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="Settings">
<MenuItem.Icon>
<Image Source="/Chalkboard_wpf;component/Resources/settings.png" />
</MenuItem.Icon>
</MenuItem>
<Style>
<Style.Triggers>
<Trigger Property="menuItem.IsMouseOver" Value="True">
<Setter Property="MenuItem.Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Menu>
I tried to add a parent "MenuItem.Style" to the "Style" element, but it apparently doesnt exist.
Any Ideas?
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
K so after reading Tao Liang's answer I tried adding the following:
But my menuitems just disappeared.
<Window.Resources>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
But my menuitems just disappeared.
The code you posted will, I think, replace the whole of the control's visual template - with a template that has no visible components!
So i need to redesign the whole thing? Just for hovering styling :D
Styling is harder than I thought
Is there maybe another way? Behind code maybe?
Styling is harder than I thought
Is there maybe another way? Behind code maybe?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
As far as I'm aware that's it - copy the existing template and tweak it.
The Windows SDK has XAML files with all the themes styles for each control.
There are also ways of retrieving the style for a control in code, but I'd have to look them up.
The Windows SDK has XAML files with all the themes styles for each control.
There are also ways of retrieving the style for a control in code, but I'd have to look them up.
Where do you find these?
"The Windows SDK has XAML files with all the themes styles for each control."
I also tried adding
But I think it overrides everything yet again :(
"The Windows SDK has XAML files with all the themes styles for each control."
I also tried adding
BasedOn="{StaticResource {x:Type MenuItem}}"
But I think it overrides everything yet again :(
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
.NET Programming
--
Questions
--
Followers
Top Experts
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.