改变HyperlinkButton的下划线(Silverlight)
2015-09-17 15:18
246 查看
HyperlinkButton默认下划线效果如左图所示,跟字非常吻合,不清晰,于是修改HyperlinkButton的样式调整下划线的位置
微软的原样式只是增加TextBlock,利用TextBlock的TextDecorations="Underline"来显示下划线,这效果显示得字重叠,下划线不清晰。
以下是微软生成的部分代码:
<Style ...> ... <Setter Property="Template"> ... <VisualState x:Name="MouseOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="UnderlineTextBlock"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> ... <TextBlock x:Name="UnderlineTextBlock" Text="{TemplateBinding Content}" TextDecorations="Underline" Visibility="Collapsed" .../> <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" .../> ... </Style>
本样式是利用Border来代替TextBlock的下划线,修改代码如下:
<Style x:Key="HyperlinkButtonStyle1" TargetType="HyperlinkButton"> <Setter Property="Foreground" Value="#FF73A9D8"/> <Setter Property="Padding" Value="2,0,2,0"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="HyperlinkButton"> <Grid Background="{TemplateBinding Background}" Cursor="{TemplateBinding Cursor}" > <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="MouseOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UnderlineBlock" Storyboard.TargetProperty="BorderThickness"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Thickness>0 0 0 1</Thickness> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Pressed" /> <VisualState x:Name="Disabled" /> </VisualStateGroup> <VisualStateGroup x:Name="FocusStates"> <VisualState x:Name="Focused"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/> </Storyboard> </VisualState> <VisualState x:Name="Unfocused"/> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <!-- <TextBlock x:Name="UnderlineTextBlock" 删除对程序没影响 --> <TextBlock x:Name="DisabledOverlay" Text="{TemplateBinding Content}" Visibility="Collapsed" Canvas.ZIndex="1" .../> <Border x:Name="UnderlineBlock" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding Foreground}" BorderThickness="0" Height="20" > <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" .../> </Border> <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Opacity="0" Stroke="#00FFFFFF" StrokeThickness="0" Visibility="Collapsed"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
------ 记录此文,为日后项目中使用----
相关文章推荐
- 从头开始敲代码之《从BaseApplication/Activity开始(三)》
- 一步一步搭建客服系统 (4) 客户列表 - JS($.ajax)调用WCF 遇到的各种坑
- 我的第一个PHP 自定义函数:验证码生成
- 黑马培训---分享点干货一 IOS面试常见的专业问题
- html的捕获与冒泡(以及冒泡解除方法)
- Java利用Zxing生成二维码
- elasticsearch 报出 Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_3_6
- bmp/gif/jpg图象最底层原理分析
- Java中的代码块(静态代码块、构造代码块、局部代码块)
- Linux shell脚本执行提示错误[[: not found
- 百度编辑器-UEditor使用注意
- Metro 风格页面设计
- 用HSSFWorkbook来对excel进行读操作
- struts2的执行原理
- 【设计模式】-单例模式-Singleton
- Combo Box CBN_SELCHANGE事件
- Android 4.4 蓝牙
- NSObject详解
- 用户态进程如何在堆栈执行代码
- html5实现表单内的上传文件框,建立一个可存取到该file的url。