簡體   English   中英

當復選框/單選按鈕處於焦點狀態時,如何設置樣式復選框/單選按鈕?

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

我想為復選框/單選按鈕設置焦點時的邊框。 這是我的代碼! 謝謝

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

這是代碼

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

我注釋了這一行,因為如果在資源中定義了這些樣式,這就是設置樣式的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM