简体   繁体   English

当复选框/单选按钮处于焦点状态时,如何设置样式复选框/单选按钮?

[英]How to set style checkbox/radiobutton when checkbox/radiobutton is focused?

I want to set border for checkbox/radiobutton when it is focused. 我想为复选框/单选按钮设置焦点时的边框。 Here is my code! 这是我的代码! Thanks 谢谢

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

Here is the code 这是代码

 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");
       }

I commented out the line as these are the ways to set style if defined in resources. 我注释了这一行,因为如果在资源中定义了这些样式,这就是设置样式的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM