[WPF]为控件中的焦点设置样式以及 FocusVisualStyle

最近的一直在用WPF,也是一边学一边用。客户对页面的要求比较高,原来一直做的Web的项目,这次是C/S结构的项目。

开发时是在Windows7做的,鼠标点击WPF元素时和用Tab使元素获得焦点后的效果不同。使用Tab时会让元素有一个虚框。在Windows XP上两种方式都会使元素有一个虚框。

查了MSDN后,发现有方法设置元素属性(FocusVisualStyle)。

 

ExpandedBlockStart.gif 代码
< Page
  
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
>
  
< Page.Resources >
    
< Style  x:Key ="MyFocusVisual" >
      
< Setter  Property ="Control.Template" >
        
< Setter.Value >
          
< ControlTemplate >
            
< Rectangle  Margin ="-2"  StrokeThickness ="1"  Stroke ="Red"  StrokeDashArray ="1 2" />
          
</ ControlTemplate >
        
</ Setter.Value >
      
</ Setter >
    
</ Style >
  
</ Page.Resources >
  
< StackPanel  Background ="Ivory"  Orientation ="Horizontal" >
    
< Canvas  Width ="10" />
    
< Button  Width ="100"  Height ="30"  FocusVisualStyle ="{DynamicResource MyFocusVisual}" >
      Focus Here
</ Button >
    
< Canvas  Width ="100" />
    
< Button  Width ="100"  Height ="30"  FocusVisualStyle ="{DynamicResource MyFocusVisual}" >
      Focus Here
</ Button >
  
</ StackPanel >
</ Page >

 

 

MSDN链接(VS.90)

焦点概述

为控件中的焦点设置样式以及 FocusVisualStyle

FrameworkElement.FocusVisualStyle 属性

FrameworkContentElement.FocusVisualStyle 属性

 

 

转载于:https://www.cnblogs.com/qishichang/archive/2010/08/31/1814035.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值