简体   繁体   English

RadioButton中的FocusVisualStyle不起作用

[英]FocusVisualStyle In RadioButton not Work

This is not working for me, focus on radio button only works when pressed the Tab key! 这对我不起作用,仅当按Tab键时,专注于单选按钮才有效! Does anyone know how to fix? 有谁知道如何解决?

 void SelectPaymentModeView_Loaded(object sender, RoutedEventArgs e)
    {
        this.radPaymentMode.Focus(); 
    }

The contents of the radiobutton is text... I also try Keyboard.Focus(this.radPaymentMode); 单选按钮的内容是文本...我也尝试使用Keyboard.Focus(this.radPaymentMode);


See the complete code: 查看完整的代码:

PaymentMode[] modes = data[1] as PaymentMode[];
if (modes.Length > 0)
{
    for (int i = 0; i < modes.Length; i++)
    {
        RadioButton rad = new RadioButton();

        rad.Name = "radPayment" + i;
        rad.GroupName = "PaymentModes";
        rad.Content = modes[i].Name;
        rad.DataContext = modes[i];
        rad.Margin = new Thickness(110, 0, 0, 5);
        rad.VerticalAlignment = System.Windows.VerticalAlignment.Center;
        rad.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
        Grid.SetRow(rad, 3 + i);
        Grid.SetColumn(rad, 1);
        gridPaymentModes.RowDefinitions.Insert(3, new RowDefinition());
        gridPaymentModes.Children.Add(rad);
        radPaymentModes.Add(rad);

        if (!string.IsNullOrEmpty((this.DataContext as Order).Payment))
        {
            String paymentOrder = rad.Content as String;
            if (paymentOrder.Equals((this.DataContext as Order).Payment))
            {
                rad.IsChecked = true;
            }
        }

        rad.Checked += new RoutedEventHandler(rad_Checked);
    }
    radPaymentModes[0].Loaded += SelectPaymentModeView_Loaded;
}

 void SelectPaymentModeView_Loaded(object sender, RoutedEventArgs e)
    {
        FocusManager.SetFocusedElement(FocusManager.GetFocusScope((sender as RadioButton)), (sender as RadioButton));
    }

The keyboard focus manager makes the dotted focus adorner visible when the keyboard is used to tab to a control (WPF wants to hide the focus rect when the mouse is used for example so there's less visual clutter). 键盘焦点管理器使您可以在使用键盘跳至控件时看到点状的焦点装饰物(例如,WPF希望在使用鼠标时隐藏焦点rect,以减少视觉混乱)。

To force it, use code like this (assuming btnRadio is your button): 要强制使用此代码,请使用以下代码(假设btnRadio是您的按钮):

    FocusManager.SetFocusedElement(FocusManager.GetFocusScope(btnRadio), btnRadio);

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

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