我想在聚焦时设置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.
}
答案 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");
}
我注释掉了这一行,因为如果在资源中定义了这些是设置样式的方法。