-
控件命名,如
<RadioButton x:Name="male"/>
。 -
在处理类中引用
using Microsoft.Maui.Handlers;
命名空间,在NavigatedTo
方法中添加属性控制代码。1 2 3 4 5 6 7 8 9 10 11 12 13 14
#if WINDOWS IRadioButtonHandler? handler = radioButtonMale.Handler as RadioButtonHandler; if (handler != null) { handler.PlatformView.IsTabStop = true; handler.PlatformView.UseSystemFocusVisuals = true; } IRadioButtonHandler? handlerf = radioButtonFemale.Handler as RadioButtonHandler; if (handlerf != null) { handlerf.PlatformView.IsTabStop = true; handlerf.PlatformView.UseSystemFocusVisuals = true; } #endif
-
在
OnAppearing
方法中使用Loaded事件进行属性设置和方法执行。1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
protected override void OnAppearing() { base.OnAppearing(); number.Loaded += delegate { number.Focus(); }; male.Loaded += Male_Loaded; female.Loaded += Female_Loaded; } private void Female_Loaded(object? sender, EventArgs e) { #if WINDOWS IRadioButtonHandler? handler = female.Handler as RadioButtonHandler; if (handler != null) { handler.PlatformView.IsTabStop = true; handler.PlatformView.UseSystemFocusVisuals = true; } #endif } private void Male_Loaded(object? sender, EventArgs e) { #if WINDOWS IRadioButtonHandler? handler = male.Handler as RadioButtonHandler; if (handler != null) { handler.PlatformView.IsTabStop = true; handler.PlatformView.UseSystemFocusVisuals = true; } #endif }