极品分享

WPF:添加超链接并hyperlink隐藏下划线

超链接,大家觉得可能很简单吧,也许说直接弄个<A>不就行了,我想说不行的呢,Wpf真的很不样呢!下面我就说说怎么弄的喽!
【前台】
<TextBlock Name="navigateTextBlock" Margin="14,0,0,5" Grid.Row="1"     TextWrapping="Wrap" Foreground="Yellow">    
         <Hyperlink Name="hyperlink0" Click="hyperlink0_Click"   NavigateUri=" http://www.google.com/" Foreground="Yellow"> 谷歌</Hyperlink>
</TextBlock>
【后台】
private void hyperlink0_Click(object sender, RoutedEventArgs e){
    System.Diagnostics.Process.Start(http://www.google.com/);  
}
【这样既可实现超链接啦!!!】
 
隐藏下划线:

<Grid.Resources>

   < Style  TargetType ="Hyperlink" >
                
< Setter  Property ="Foreground"  Value ="#209AC2" />
                
<!-- 清除文字修饰(去掉下划线) -->
                
< Setter  Property ="TextBlock.TextDecorations"  Value =" {x:Null} " />
                
< Style.Triggers >
                    
< Trigger  Property ="IsMouseOver"  Value ="True" >
                        
< Setter  Property ="Foreground"  Value ="#F27D00"   />
                        
<!-- 在鼠标悬停时显示下划线 -->
                        
< Setter  Property ="TextBlock.TextDecorations" >
                            
< Setter.Value >
                                
< TextDecorationCollection >
                                    
< TextDecoration  Location ="Underline" />
                                
</ TextDecorationCollection >
                            
</ Setter.Value >
                        
</ Setter >
                    
</ Trigger >
                
</ Style.Triggers >
            
</ Style >

</Grid.Resources>

 

2013-04-07 0 /
NET学习
/
标签: 

评论回复

回到顶部