3
3
using Microsoft . Extensions . DependencyInjection ;
4
4
using Microsoft . Extensions . Hosting ;
5
5
using Microsoft . Maui . Controls . Compatibility ;
6
+ using Microsoft . Maui . Hosting ;
7
+ using Microsoft . Maui . Controls . Shapes ;
8
+ using Microsoft . Maui . LifecycleEvents ;
9
+ using Microsoft . Maui . Graphics ;
6
10
7
11
#if __ANDROID__
8
12
using Microsoft . Maui . Controls . Compatibility . Platform . Android ;
9
13
using Microsoft . Maui . Controls . Compatibility . Platform . Android . AppCompat ;
14
+ using Microsoft . Maui . Graphics . Native ;
10
15
using FrameRenderer = Microsoft . Maui . Controls . Compatibility . Platform . Android . FastRenderers . FrameRenderer ;
11
16
using LabelRenderer = Microsoft . Maui . Controls . Compatibility . Platform . Android . FastRenderers . LabelRenderer ;
12
17
using ImageRenderer = Microsoft . Maui . Controls . Compatibility . Platform . Android . FastRenderers . ImageRenderer ;
13
18
using ButtonRenderer = Microsoft . Maui . Controls . Compatibility . Platform . Android . FastRenderers . ButtonRenderer ;
14
19
using DefaultRenderer = Microsoft . Maui . Controls . Compatibility . Platform . Android . AppCompat . Platform . DefaultRenderer ;
15
20
#elif WINDOWS
16
21
using Microsoft . Maui . Controls . Compatibility . Platform . UWP ;
22
+ using Microsoft . Maui . Graphics . Win2D ;
17
23
using BoxRenderer = Microsoft . Maui . Controls . Compatibility . Platform . UWP . BoxViewBorderRenderer ;
18
24
using CellRenderer = Microsoft . Maui . Controls . Compatibility . Platform . UWP . TextCellRenderer ;
19
25
using Deserializer = Microsoft . Maui . Controls . Compatibility . Platform . UWP . WindowsSerializer ;
20
26
using ResourcesProvider = Microsoft . Maui . Controls . Compatibility . Platform . UWP . WindowsResourcesProvider ;
21
27
using StreamImagesourceHandler = Microsoft . Maui . Controls . Compatibility . Platform . UWP . StreamImageSourceHandler ;
22
28
using ImageLoaderSourceHandler = Microsoft . Maui . Controls . Compatibility . Platform . UWP . UriImageSourceHandler ;
23
29
using DefaultRenderer = Microsoft . Maui . Controls . Compatibility . Platform . UWP . DefaultRenderer ;
24
-
25
30
#elif __IOS__
26
31
using Microsoft . Maui . Controls . Compatibility . Platform . iOS ;
32
+ using Microsoft . Maui . Graphics . Native ;
27
33
using WebViewRenderer = Microsoft . Maui . Controls . Compatibility . Platform . iOS . WkWebViewRenderer ;
28
34
using NavigationPageRenderer = Microsoft . Maui . Controls . Compatibility . Platform . iOS . NavigationRenderer ;
29
35
using TabbedPageRenderer = Microsoft . Maui . Controls . Compatibility . Platform . iOS . TabbedRenderer ;
32
38
using DefaultRenderer = Microsoft . Maui . Controls . Compatibility . Platform . iOS . Platform . DefaultRenderer ;
33
39
#endif
34
40
35
- using Microsoft . Maui . Hosting ;
36
- using Microsoft . Maui . Controls . Shapes ;
37
- using Microsoft . Maui . LifecycleEvents ;
38
-
39
41
namespace Microsoft . Maui . Controls . Hosting
40
42
{
41
43
public static class AppHostBuilderExtensions
@@ -70,33 +72,34 @@ static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder)
70
72
{
71
73
#if __ANDROID__
72
74
events . AddAndroid ( android => android
73
- . OnCreate ( ( a , b ) =>
74
- {
75
- // This just gets Forms Compat bits setup with what it needs
76
- // to initialize the first view. MauiContext hasn't been initialized at this point
77
- // so we setup one that will look exactly the same just
78
- // to make legacy Forms bits happy
79
- var services = MauiApplication . Current . Services ;
80
- MauiContext mauiContext = new MauiContext ( services , a ) ;
81
- ActivationState state = new ActivationState ( mauiContext , b ) ;
82
- Forms . Init ( new ActivationState ( mauiContext , b ) , new InitializationOptions ( ) { Flags = InitializationFlags . SkipRenderers } ) ;
83
- } )
84
- . OnPostCreate ( ( _ , b ) =>
85
- {
86
- // This calls Init again so that the MauiContext that's part of
87
- // Forms.Init matches the rest of the maui application
88
- var mauiApp = MauiApplication . Current . Application ;
89
- if ( mauiApp . Windows . Count > 0 )
90
- {
91
- var window = mauiApp . Windows [ 0 ] ;
92
- var mauiContext = window . Handler ? . MauiContext ?? window . View . Handler ? . MauiContext ;
75
+ . OnCreate ( ( a , b ) =>
76
+ {
77
+ // This just gets Forms Compat bits setup with what it needs
78
+ // to initialize the first view. MauiContext hasn't been initialized at this point
79
+ // so we setup one that will look exactly the same just
80
+ // to make legacy Forms bits happy
81
+ var services = MauiApplication . Current . Services ;
82
+ MauiContext mauiContext = new MauiContext ( services , a ) ;
83
+ ActivationState state = new ActivationState ( mauiContext , b ) ;
84
+ Forms . Init ( new ActivationState ( mauiContext , b ) , new InitializationOptions ( ) { Flags = InitializationFlags . SkipRenderers } ) ;
85
+ GraphicsPlatform . RegisterGlobalService ( NativeGraphicsService . Instance ) ;
86
+ } )
87
+ . OnPostCreate ( ( _ , b ) =>
88
+ {
89
+ // This calls Init again so that the MauiContext that's part of
90
+ // Forms.Init matches the rest of the maui application
91
+ var mauiApp = MauiApplication . Current . Application ;
92
+ if ( mauiApp . Windows . Count > 0 )
93
+ {
94
+ var window = mauiApp . Windows [ 0 ] ;
95
+ var mauiContext = window . Handler ? . MauiContext ?? window . View . Handler ? . MauiContext ;
93
96
94
- if ( mauiContext != null )
95
- {
96
- Forms . Init ( new ActivationState ( mauiContext , b ) ) ;
97
- }
98
- }
99
- } ) ) ;
97
+ if ( mauiContext != null )
98
+ {
99
+ Forms . Init ( new ActivationState ( mauiContext , b ) ) ;
100
+ }
101
+ }
102
+ } ) ) ;
100
103
#elif __IOS__
101
104
events . AddiOS ( iOS =>
102
105
{
@@ -112,6 +115,7 @@ static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder)
112
115
// This calls Init again so that the MauiContext that's part of
113
116
// Forms.Init matches the rest of the maui application
114
117
var mauiApp = MauiUIApplicationDelegate . Current . Application ;
118
+
115
119
if ( mauiApp . Windows . Count > 0 )
116
120
{
117
121
var window = mauiApp . Windows [ 0 ] ;
@@ -122,38 +126,42 @@ static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder)
122
126
Forms . Init ( new ActivationState ( mauiContext ) ) ;
123
127
}
124
128
}
129
+
130
+ GraphicsPlatform . RegisterGlobalService ( NativeGraphicsService . Instance ) ;
131
+
125
132
return true ;
126
133
} ) ;
127
134
} ) ;
128
135
#elif WINDOWS
129
136
events . AddWindows ( windows => windows
130
- . OnLaunching ( ( _ , args ) =>
131
- {
132
- // We need to call Forms.Init so the Window and Root Page can new up successfully
133
- // The dispatcher that's inside of Forms.Init needs to be setup before the initial
134
- // window and root page start creating
135
- // Inside OnLaunched we grab the MauiContext that's on the window so we can have the correct
136
- // MauiContext inside Forms
137
- MauiContext mauiContext = new MauiContext ( MauiWinUIApplication . Current . Services , new UI . Xaml . Window ( ) ) ;
138
- ActivationState state = new ActivationState ( mauiContext , args ) ;
139
- Forms . Init ( state , new InitializationOptions ( ) { Flags = InitializationFlags . SkipRenderers } ) ;
140
- } )
141
- . OnLaunched ( ( _ , args ) =>
142
- {
143
- // This calls Init again so that the MauiContext that's part of
144
- // Forms.Init matches the rest of the maui application
145
- var mauiApp = MauiWinUIApplication . Current . Application ;
146
- if ( mauiApp . Windows . Count > 0 )
147
- {
148
- var window = mauiApp . Windows [ 0 ] ;
149
- var mauiContext = window . Handler ? . MauiContext ?? window . View . Handler ? . MauiContext ;
137
+ . OnLaunching ( ( _ , args ) =>
138
+ {
139
+ // We need to call Forms.Init so the Window and Root Page can new up successfully
140
+ // The dispatcher that's inside of Forms.Init needs to be setup before the initial
141
+ // window and root page start creating
142
+ // Inside OnLaunched we grab the MauiContext that's on the window so we can have the correct
143
+ // MauiContext inside Forms
144
+ MauiContext mauiContext = new MauiContext ( MauiWinUIApplication . Current . Services , new UI . Xaml . Window ( ) ) ;
145
+ ActivationState state = new ActivationState ( mauiContext , args ) ;
146
+ Forms . Init ( state , new InitializationOptions ( ) { Flags = InitializationFlags . SkipRenderers } ) ;
147
+ GraphicsPlatform . RegisterGlobalService ( W2DGraphicsService . Instance ) ;
148
+ } )
149
+ . OnLaunched ( ( _ , args ) =>
150
+ {
151
+ // This calls Init again so that the MauiContext that's part of
152
+ // Forms.Init matches the rest of the maui application
153
+ var mauiApp = MauiWinUIApplication . Current . Application ;
154
+ if ( mauiApp . Windows . Count > 0 )
155
+ {
156
+ var window = mauiApp . Windows [ 0 ] ;
157
+ var mauiContext = window . Handler ? . MauiContext ?? window . View . Handler ? . MauiContext ;
150
158
151
- if ( mauiContext != null )
152
- {
153
- Forms . Init ( new ActivationState ( mauiContext , args ) ) ;
154
- }
155
- }
156
- } ) ) ;
159
+ if ( mauiContext != null )
160
+ {
161
+ Forms . Init ( new ActivationState ( mauiContext , args ) ) ;
162
+ }
163
+ }
164
+ } ) ) ;
157
165
#endif
158
166
} ) ;
159
167
@@ -182,7 +190,7 @@ static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder)
182
190
handlers . TryAddCompatibilityRenderer ( typeof ( Line ) , typeof ( LineRenderer ) ) ;
183
191
handlers . TryAddCompatibilityRenderer ( typeof ( Polyline ) , typeof ( PolylineRenderer ) ) ;
184
192
handlers . TryAddCompatibilityRenderer ( typeof ( Polygon ) , typeof ( PolygonRenderer ) ) ;
185
- handlers . TryAddCompatibilityRenderer ( typeof ( Rectangle ) , typeof ( RectangleRenderer ) ) ;
193
+ handlers . TryAddCompatibilityRenderer ( typeof ( Shapes . Rectangle ) , typeof ( RectangleRenderer ) ) ;
186
194
handlers . TryAddCompatibilityRenderer ( typeof ( RadioButton ) , typeof ( RadioButtonRenderer ) ) ;
187
195
handlers . TryAddCompatibilityRenderer ( typeof ( Slider ) , typeof ( SliderRenderer ) ) ;
188
196
handlers . TryAddCompatibilityRenderer ( typeof ( WebView ) , typeof ( WebViewRenderer ) ) ;
0 commit comments