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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.