在WPF中悬停文本块时前景色不会改变 [英] Foreground color not change on hover of textblock in WPF

查看:68
本文介绍了在WPF中悬停文本块时前景色不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在Wpf工作我在文本块上设置Trigger以更改背景和前景但前景颜色不会改变..



请帮助...



我的代码是



 <  样式    x:键  =  LeftHoverBackground    TargetType   =  {x:Type TextBlock} >  
< ; Setter Property = TextBlock .ForegroundValue =#404041/>
< Style .Triggers>
< Trigger Property =IsMouseOverValue =True>
< Setter Property =TextBlock.ForegroundValue =White>
< / Setter >
< Setter 属性 = 背景 = #1A1A1A >
< / Setter >

< / Trigger >
< / Style.Triggers >
< / Style >

解决方案

您是否在 Textblock 上明确设置了样式?

如果样式有 x:Key 属性然后你需要指定该id使用的样式;

< TextBlock Text =WoohooStyle = {StaticResource LeftHoverBackground}/> 





希望这会有所帮助,

Fredrik


这是我的Xml代码..

我想在文本块悬停时更改标签和背景颜色



 <   textblock     dockpanel.dock   = 热门 >  
< dockpanel >
< ; textblock width < span class =code-keyword> =
242 高度 = 52 名称 = NewsFeedControlTextBlock dockpanel.dock = Top style = {StaticResource LeftHoverBackground} >
< 超链接 textdecorations = cursor = >
< inlineuicontainer >
< dockpanel 宽度 = 242 height = 52 >
< image source = ../ Resources / Images / menuseperator.png renderoptions.bitmapscalingmode = NearestNeighbor 拉伸 = dockpanel.dock = 底部 > < / image >
< image source = ../资源/Images/newsfeed.png\" renderoptions.bitmapscalingmode = NearestNeighbor stretch = < span class =code-attribute> dockpanel.dock = margin = 15,0,0,0 verticalalignment = 中心 名称 = newsFeedIcon > < / image >

< 标签 内容 = 新闻源 DockPanel.Dock = Top 保证金 = 5,0,0,0 FontSize = 14px FontFamily = 资源/字体/#Lato 名称 = lblNewsFeed VerticalAlignment = 中心 / >

< / dockpanel < span class =code-keyword>>
< / inlineuicontainer >
< / hyperlink >
< /文本块 > < / dockpanel > < / textblock >


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

<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>

解决方案

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


Here is my Xml Code..
and i want to change lable and background color on textblock hover

<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>


这篇关于在WPF中悬停文本块时前景色不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆