Click to See Complete Forum and Search --> : Menu Item color change in wpf
syr
April 26th, 2009, 11:35 AM
Hi ,
I have attaached with my project window menu bar for review .
When i selected menu item its highlited with blue color .i dont want that color bec my req is like that.
Please send me reply asap. bec its very urgent for me.
please review the attachment.
MMH
April 27th, 2009, 05:44 AM
Put Background as white: something like this.
<MenuItem x:Name="mnuFile" Header="File" Background="White" Foreground="SteelBlue"/>
It will remove Blue hovering effect.
I hope this is what you want.
syr
April 27th, 2009, 09:32 AM
Thanks for your reply and its not working for me.please let me know.
MMH
April 27th, 2009, 11:47 AM
Thanks for your reply and its not working for me.please let me know.
Can you paste the lines of code that you have coded for menu item ?
syr
April 27th, 2009, 01:24 PM
Please check the following code.Thanks for your fast reply.
<Menu Margin="12,0,0,0" Name="menuManageData" Height="26" VerticalAlignment="Top" Background="White" HorizontalAlignment="Left" Width="302">
<MenuItem Header="Search For Form" Click="SearchFrm_Click" Foreground="#FF0093BD" ForceCursor="True" Background="White" FontFamily="Arial" OverridesDefaultStyle="False" Focusable="True" HeaderStringFormat="Bold" />
<MenuItem Header="Search and Replace" Click="SearchReplace_Click" Foreground="#FF0093BD" FontFamily="Arial" />
<MenuItem Header="Add New Form" Foreground="#FF0093BD" Click="AddNewFrm_Click" Background="White" FontFamily="Arial" />
</Menu>
MMH
April 28th, 2009, 01:29 AM
Please check the following code.Thanks for your fast reply.
<Menu Margin="12,0,0,0" Name="menuManageData" Height="26" VerticalAlignment="Top" Background="White" HorizontalAlignment="Left" Width="302">
<MenuItem Header="Search For Form" Click="SearchFrm_Click" Foreground="#FF0093BD" ForceCursor="True" Background="White" FontFamily="Arial" OverridesDefaultStyle="False" Focusable="True" HeaderStringFormat="Bold" />
<MenuItem Header="Search and Replace" Click="SearchReplace_Click" Foreground="#FF0093BD" FontFamily="Arial" />
<MenuItem Header="Add New Form" Foreground="#FF0093BD" Click="AddNewFrm_Click" Background="White" FontFamily="Arial" />
</Menu>
Hi, Can you tell me whether setting Background = "White" for menuItem works? or doent not work completely?
In your code i found that, for 2nd menuItem Background="White" is missed out.
Please check it. I have tested this in both VS2008 and VS2008 EE.
syr
April 28th, 2009, 09:32 AM
I am using C# 2008 express edition and when i change the background to white to all menu items still it is showing blue whem mouse hover.
Thank you for your continuous support .
MMH
April 28th, 2009, 11:43 AM
I am using C# 2008 express edition and when i change the background to white to all menu items still it is showing blue whem mouse hover.
Thank you for your continuous support .
Whenever you want to change the appearance of a control, consider using Control Templates. Put this code in App.xaml.
I would recommend you to make a separate resource file and put the below code. You can google to know how to use resource file.
<Style x:Key="{x:Type Menu}" TargetType="{x:Type Menu}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Menu}">
<Border
Background="White"
BorderBrush="Transparent"
BorderThickness="1">
<StackPanel ClipToBounds="True" Orientation="Horizontal" IsItemsHost="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate
x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}"
TargetType="{x:Type MenuItem}">
<Border Name="Border" >
<Grid>
<ContentPresenter
Margin="6,3,6,3"
ContentSource="Header"
RecognizesAccessKey="True" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="true">
<Setter TargetName="Border" Property="Background" Value="White"/>
<Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
syr
April 28th, 2009, 11:10 PM
Thanks its worked.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.