当复选框/ radiobutton聚焦时,如何设置样式复选框/单选按钮?

时间:2017-09-12 02:46:09

标签: c# wpf

我想在聚焦时设置checkbox / radiobutton的边框。 这是我的代码!感谢

 UIElement element = container;
 DependencyObject obj2 = FocusManager.GetIsFocusScope(element) ? element : 
 FocusManager.GetFocusScope(element);
 IInputElement focusedElement = FocusManager.GetFocusedElement(obj2);
 object obj = focusedElement;

 if (obj != null && (obj.GetType() == typeof(CheckBox) || obj.GetType() == 
     typeof(RadioButton)))
   {
  //Set style when focus for Checkbox, radiobutton. 
   }

1 个答案:

答案 0 :(得分:0)

  

这是代码

 if (obj != null && (obj.GetType() == typeof(CheckBox) || obj.GetType() == 
         typeof(RadioButton)))
       {
         var element = obj as FrameworkElement;
         // element.Style =  Resources["ResourceName"] as Style;
         // or 
         //  element.Style = (Style) FindResource("YourResourceKey");
       }

我注释掉了这一行,因为如果在资源中定义了这些是设置样式的方法。