1
- namespace MauiBlazorApp
1
+ using MauiBlazorApp . Extensions ;
2
+
3
+ namespace MauiBlazorApp
2
4
{
3
5
public partial class MainPage : ContentPage
4
6
{
@@ -12,80 +14,39 @@ public MainPage()
12
14
13
15
private void InitializeComponent ( )
14
16
{
15
- SetDynamicResource ( BackgroundColorProperty , "SecondaryColor" ) ;
16
- var grid1 = new Grid ( )
17
- {
18
- RowSpacing = 25 ,
19
- Padding = Device . RuntimePlatform switch
20
- {
21
- Device . iOS => new Thickness ( 30 , 60 , 30 , 30 ) ,
22
- _ => new Thickness ( 30 ) ,
23
- } ,
24
- RowDefinitions = Rows . Define ( Auto , Auto , Auto , Auto , Star )
25
- } ;
26
-
27
- var label1 = new Label ( )
28
- {
29
- Text = "Hello, World!" ,
30
- FontSize = 32 ,
31
- HorizontalOptions = LayoutOptions . Center
32
- } ;
33
-
34
- GridLayout . SetRow ( label1 , 0 ) ;
35
- SemanticProperties . SetHeadingLevel ( label1 , SemanticHeadingLevel . Level1 ) ;
36
-
37
- var label2 = new Label ( )
38
- {
39
- Text = "Welcome to .NET Multi-platform App UI" ,
40
- FontSize = 16 ,
41
- HorizontalOptions = LayoutOptions . Center
42
- } ;
43
-
44
- GridLayout . SetRow ( label2 , 1 ) ;
45
- SemanticProperties . SetHeadingLevel ( label2 , SemanticHeadingLevel . Level1 ) ;
46
- SemanticProperties . SetDescription ( label2 , "Welcome to dot net Multi platform App U I" ) ;
47
-
48
- counter = new Label ( )
49
- {
50
- Text = "Current count: 0" ,
51
- FontSize = 18 ,
52
- FontAttributes = FontAttributes . Bold ,
53
- HorizontalOptions = LayoutOptions . Center
54
- } ;
55
-
56
- GridLayout . SetRow ( counter , 2 ) ;
57
-
58
- var button1 = new Button ( )
59
- {
60
- Text = "Click me" ,
61
- FontAttributes = FontAttributes . Bold ,
62
- HorizontalOptions = LayoutOptions . Center
63
- } ;
64
-
65
- button1 . Clicked += OnCounterClicked ;
66
- GridLayout . SetRow ( button1 , 3 ) ;
67
- SemanticProperties . SetHint ( button1 , "Counts the number of times you click" ) ;
68
-
69
- var image1 = new Image ( )
70
- {
71
- Source = "dotnet_bot.png" ,
72
- HorizontalOptions = LayoutOptions . Center ,
73
- WidthRequest = 250 ,
74
- HeightRequest = 310
75
- } ;
76
-
77
- GridLayout . SetRow ( image1 , 4 ) ;
78
- SemanticProperties . SetDescription ( image1 , "Cute dotnet bot waving hi to you!" ) ;
79
-
80
- grid1 . Add ( label1 ) ;
81
- grid1 . Add ( label2 ) ;
82
- grid1 . Add ( counter ) ;
83
- grid1 . Add ( button1 ) ;
84
- grid1 . Add ( image1 ) ;
85
-
86
17
Content = new ScrollView ( )
87
18
{
88
- Content = grid1
19
+ Content = new Grid ( )
20
+ {
21
+ RowSpacing = 25 ,
22
+ RowDefinitions = Rows . Define ( Auto , Auto , Auto , Auto , Star ) ,
23
+ Children =
24
+ {
25
+ new Label ( ) { Text = "Hello, World!" } . Row ( 0 )
26
+ . FontSize ( 32 )
27
+ . CenterHorizontal ( )
28
+ . SemanticHeading ( SemanticHeadingLevel . Level1 ) ,
29
+ new Label ( ) { Text = "Welcome to .NET Multi-platform App UI" } . Row ( 1 )
30
+ . FontSize ( 18 )
31
+ . CenterHorizontal ( )
32
+ . SemanticHeading ( SemanticHeadingLevel . Level1 )
33
+ . SemanticDesc ( "Welcome to dot net Multi platform App U I" ) ,
34
+ new Label ( ) { Text = "Current count: 0" } . Row ( 2 )
35
+ . Bold ( )
36
+ . FontSize ( 18 )
37
+ . CenterHorizontal ( )
38
+ . Assign ( out counter ) ,
39
+ new Button ( ) { Text = "Click me" } . Row ( 3 )
40
+ . Bold ( )
41
+ . CenterHorizontal ( )
42
+ . Invoke ( btn => btn . Clicked += OnCounterClicked )
43
+ . SemanticHint ( "Counts the number of times you click" ) ,
44
+ new Image ( ) { Source = "dotnet_bot.png" } . Row ( 4 )
45
+ . Size ( 250 , 310 )
46
+ . CenterHorizontal ( )
47
+ . SemanticDesc ( "Cute dot net bot waving hi to you!" ) ,
48
+ }
49
+ } . Padding ( Device . RuntimePlatform switch { Device . iOS => new Thickness ( 30 , 60 , 30 , 30 ) , _ => new Thickness ( 30 ) } )
89
50
} ;
90
51
}
91
52
0 commit comments