locked
Change the Menu Foreground Color in Windows XP does not work. RRS feed

  • Question

  • Hi People! I'm trying to change the foreground color of a Menu object (using templates) but it does not work on Windows XP.

    It works perfectly when I run the same application in Windows Vista. Does anybody knows if is there an workaround for this in Windows XP ? Below is a small piece code that reproduces the problem.

    ========================= BEGIN OF CODE =============================
    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    	
    	<Window.Resources>
    		<LinearGradientBrush x:Key="MenuBackground" EndPoint="0,1" StartPoint="0,0">
    			<GradientStop Color="#F6F6F6" Offset="0.25"/>
    			<GradientStop Color="#EAE8E8" Offset="0.25"/>
    			<GradientStop Color="#DCD9D9" Offset="0.8"/>
    			<GradientStop Color="White" Offset="1"/>
    		</LinearGradientBrush>
    		<Style x:Key="MenuStyle1" TargetType="{x:Type Menu}">
    			<Setter Property="Background" Value="{StaticResource MenuBackground}"/>
    			<Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
    			<Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
    			<Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
    			<Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
    			<Setter Property="Foreground" Value="Red"/> <!-- This line works fine on Vista but not on XP -->
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type Menu}">
    						<Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
    							<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    						</Border>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    	</Window.Resources>
    
    	<Grid x:Name="LayoutRoot">
    		<Grid.RowDefinitions>
    			<RowDefinition Height="Auto"/>
    			<RowDefinition Height="*"/>
    		</Grid.RowDefinitions>
    		<Menu Style="{DynamicResource MenuStyle1}">
    			<MenuItem Header="MenuItem">
    				<MenuItem Header="Item 1"/>
    				<MenuItem Header="Item 2"/>
    				<MenuItem Header="Item 3"/>
    			</MenuItem>
    		</Menu>
    	</Grid>
    	
    </Window>
    ========================= END OF CODE =============================

    Running this program on Vista, you will have the menu rendered in red as expected, but on XP the menu reders with its default system color.

    Thanks a lot for any help or idea in advance.

    Rodrigo.

    Vista Ultimate SP2
    XP Professional SP3
    NET Framework 3.5 SP1
    Expression Blend 3
    Windows Update and drivers up to date on both systems.
    Wednesday, October 21, 2009 12:55 AM