Maui设置控件全局属性

Maui设置控件全局属性

MauiProgram.cs文件CreateMauiApp方法下添加代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
EntryHandler.Mapper.AppendToMapping("NoKeyboardEntry", (handler, entry) =>
            {
#if ANDROID
                // 隐藏软键盘
                handler.PlatformView.ShowSoftInputOnFocus = false;
                handler.PlatformView.ImeOptions= Android.Views.InputMethods.ImeAction.ImeNull;
                handler.PlatformView.InputType= Android.Text.InputTypes.Null;

#endif
            });
            ButtonHandler.Mapper.AppendToMapping("Project.Buttons.NoSystemFocus", (handler, view) =>
            {
#if ANDROID
                if (view is Button)
                {
                    handler.PlatformView.FocusableInTouchMode = false;
                    handler.PlatformView.Focusable = false;
                }
#endif
            });
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 RadioButtonHandler.Mapper.AppendToMapping("tt", (handler, view) =>
 {
     handler.PlatformView.UseSystemFocusVisuals = false;
     handler.PlatformView.IsTabStop = false;
 });
 LabelHandler.Mapper.AppendToMapping("tt", (handler, view) =>
 {
     handler.PlatformView.UseSystemFocusVisuals = false;
     handler.PlatformView.IsTabStop = false;
 });
  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
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
            //WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
            //{
            //    var window = handler.PlatformView.GetAppWindow();
            //    if (window != null)
            //    {
            //        // resize & center to something we like
            //        var display = DisplayArea.GetFromWindowId(window.Id, DisplayAreaFallback.Nearest);
            //        const int width = 480;
            //        const int height = 640;
            //        window.MoveAndResize(new RectInt32((display.WorkArea.Width - width) / 2, (display.WorkArea.Height - height) / 2, width, height));

            //        // prevent resizing
            //        if (window.Presenter is OverlappedPresenter presenter)
            //        {
            //            presenter.IsResizable = false;
            //            presenter.IsMaximizable = false;
            //            presenter.IsMinimizable = false;
            //        }
            //    }
            //});
            //            Microsoft.Maui.Handlers.PageHandler.Mapper.AppendToMapping(nameof(PageHandler), (handler, view) =>
            //            {
#if WINDOWS
            //                handler.PlatformView.PreviewKeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.PreviewKeyDown += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyDown += (sender, e) =>
            //                {

            //                };
            //#endif
            //            });
            //            Microsoft.Maui.Handlers.ActivityIndicatorHandler.Mapper.AppendToMapping(nameof(PageHandler), (handler, view) =>
            //            {
            //#if WINDOWS
            //                handler.PlatformView.PreviewKeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.PreviewKeyDown += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyDown += (sender, e) =>
            //                {

            //                };
            //#endif
            //            });
            //            Microsoft.Maui.Handlers.ContentViewHandler.Mapper.AppendToMapping(nameof(PageHandler), (handler, view) =>
            //            {
            //#if WINDOWS
            //                handler.PlatformView.PreviewKeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.PreviewKeyDown += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyDown += (sender, e) =>
            //                {

            //                };
            //#endif
            //            });
            //            Microsoft.Maui.Handlers.FlyoutViewHandler.Mapper.AppendToMapping(nameof(PageHandler), (handler, view) =>
            //            {
            //#if WINDOWS
            //                handler.PlatformView.PreviewKeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.PreviewKeyDown += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyDown += (sender, e) =>
            //                {

            //                };
            //#endif
            //            });
            //            Microsoft.Maui.Handlers.BorderHandler.Mapper.AppendToMapping(nameof(PageHandler), (handler, view) =>
            //            {
            //#if WINDOWS
            //                handler.PlatformView.PreviewKeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.PreviewKeyDown += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyDown += (sender, e) =>
            //                {

            //                };
            //#endif
            //            });
            //            Microsoft.Maui.Handlers.LayoutHandler.Mapper.AppendToMapping(nameof(PageHandler), (handler, view) =>
            //            {
            //#if WINDOWS
            //                handler.PlatformView.PreviewKeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.PreviewKeyDown += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyUp += (sender, e) =>
            //                {

            //                };
            //                handler.PlatformView.KeyDown += (sender, e) =>
            //                {

            //                };
            //#endif
            //            });
            //            

            ButtonHandler.Mapper.AppendToMapping("Project.Buttons.NoSystemFocus", (IButtonHandler handler, IButton view) =>
            {
                if (view is Button)
                {
                    handler.PlatformView.UseSystemFocusVisuals = false;
                    handler.PlatformView.IsTabStop = false;
                }
            });
            ImageButtonHandler.Mapper.AppendToMapping("Project.ImageBButtons.NoSystemFocus", (handler, view) =>
            {
                if (view is ImageButton)
                {
                    handler.PlatformView.UseSystemFocusVisuals = false;
                    handler.PlatformView.IsTabStop = false;
                }
            });
            //LayoutHandler.Mapper.AppendToMapping("Project.Buttons.NoSystemFocus", (handler, view) =>
            //{
            //    //if (view is ImageButton)
            //    {
            //        handler.PlatformView.UseSystemFocusVisuals = false;
            //        handler.PlatformView.IsTabStop = false;
            //    }
            //});
            CollectionViewHandler.Mapper.AppendToMapping("tt", (handler, view) =>
            {
                if (handler.PlatformView.ItemsPanelRoot != null)
                {
                    foreach (var item in handler.PlatformView.ItemsPanelRoot.Children)
                    {
                        item.IsTabStop = false;
                    }
                }
                
                handler.PlatformView.IsTabStop = false;
                //handler.PlatformView.KeyboardAcceleratorPlacementMode = Microsoft.UI.Xaml.Input.KeyboardAcceleratorPlacementMode.Hidden;
                //handler.PlatformView.TabFocusNavigation = Microsoft.UI.Xaml.Input.KeyboardNavigationMode.Once;
                //handler.PlatformView.TabIndex = -1;
                //handler.PlatformView.TabNavigation = Microsoft.UI.Xaml.Input.KeyboardNavigationMode.Once;
                //handler.VirtualView.Unfocus();

                //if (handler.HasContainer)
                //{

                //}
            });

Syncfusion库禁用Tab焦点。

1
2
3
4
5
6
7
Syncfusion.Maui.Graphics.Internals.SfDrawableViewHandler.ViewMapper.AppendToMapping("tt", (handler, view) =>
{
    if (handler is Syncfusion.Maui.Graphics.Internals.SfDrawableViewHandler viewHandler)
    {
        viewHandler.PlatformView.IsTabStop = false;
    }
});
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy