Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I am working in Wpf I set Trigger on textblock for Change Background and Foreground But Foreground Color is Not Change..

Please Help...

my code is

HTML
<Style x:Key="LeftHoverBackground" TargetType="{x:Type TextBlock}">
            <Setter Property= "TextBlock.Foreground" Value="#404041"/>            
            <Style.Triggers>                
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="TextBlock.Foreground" Value="White">
                    </Setter>
                    <Setter Property="Background" Value="#1A1A1A">
                    </Setter>
                    
                </Trigger>
            </Style.Triggers>
        </Style>
Posted
Updated 31-Aug-14 22:43pm
v2

Have you set the style explicitly on the Textblock?
If the style has a x:Key attribute then you need to specify the style to be used by that id;
<TextBlock Text="Woohoo" Style="{StaticResource LeftHoverBackground}"/>


Hope this helps,
Fredrik
 
Share this answer
 
Comments
akashjg 1-Sep-14 5:14am    
Hello Fredrik
i already set the key...
Here is my Xml Code..
and i want to change lable and background color on textblock hover

HTML
<textblock dockpanel.dock="Top">            
            <dockpanel>
            <textblock width="242" height="52" name="NewsFeedControlTextBlock" dockpanel.dock="Top" style="{StaticResource LeftHoverBackground}">
            <hyperlink textdecorations="None" cursor="Hand">
                <inlineuicontainer>
                    <dockpanel width="242" height="52">                         
                        <image source="../Resources/Images/menuseperator.png" renderoptions.bitmapscalingmode="NearestNeighbor" stretch="None" dockpanel.dock="Bottom"></image>    
                         <image source="../Resources/Images/newsfeed.png" renderoptions.bitmapscalingmode="NearestNeighbor" stretch="None" dockpanel.dock="Left" margin="15,0,0,0" verticalalignment="Center" name="newsFeedIcon"></image>    
                        
                        <Label Content="News Feeds" DockPanel.Dock="Top" Margin="5,0,0,0" FontSize="14px"  FontFamily="Resources/Fonts/#Lato" Name="lblNewsFeed" VerticalAlignment="Center" />
                        
                    </dockpanel>
                </inlineuicontainer>
            </hyperlink>
        </textblock>  </dockpanel></textblock>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900