@@ -102,55 +102,108 @@ private ContentPage CreateTab1()
102
102
new Label
103
103
{
104
104
HorizontalTextAlignment = TextAlignment . Center ,
105
- Text = "Welcome to Xamarin Forms Tab1!"
105
+ Text = "Xamarin Forms Tab Badge Sample" ,
106
+ FontSize = 14 ,
107
+ FontAttributes = FontAttributes . Bold
106
108
} ,
107
109
}
108
110
} ;
109
111
110
- var buttonIncrement = new Button { Text = "Increment" } ;
111
- buttonIncrement . SetBinding ( Button . CommandProperty , "IncrementCommand" ) ;
112
- var buttonDecrement = new Button { Text = "Decrement" } ;
113
- buttonDecrement . SetBinding ( Button . CommandProperty , "DecrementCommand" ) ;
114
-
115
- tab1Layout . Children . Add ( buttonIncrement ) ;
116
- tab1Layout . Children . Add ( buttonDecrement ) ;
112
+ var stepper = new Stepper
113
+ {
114
+ Increment = 1 ,
115
+ Maximum = 111 ,
116
+ Minimum = 0 ,
117
+ VerticalOptions = LayoutOptions . Center
118
+ } ;
119
+
120
+ stepper . SetBinding ( Stepper . ValueProperty , nameof ( Tab1ViewModel . CountValue ) , BindingMode . TwoWay ) ;
121
+
122
+ var grid = new Grid ( ) ;
123
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
124
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
125
+ grid . Children . Add ( new Label { Text = "Increment / Decrement Value: " , HorizontalTextAlignment = TextAlignment . End , VerticalTextAlignment = TextAlignment . Center } , 0 , 0 ) ;
126
+ grid . Children . Add ( stepper , 1 , 0 ) ;
127
+ tab1Layout . Children . Add ( grid ) ;
117
128
118
129
var buttonChangeColor = new Button { Text = "Change Color" } ;
119
- buttonChangeColor . SetBinding ( Button . CommandProperty , " ChangeColorCommand" ) ;
130
+ buttonChangeColor . SetBinding ( Button . CommandProperty , nameof ( Tab1ViewModel . ChangeColorCommand ) ) ;
120
131
tab1Layout . Children . Add ( buttonChangeColor ) ;
121
132
122
133
var buttonChangeTextColor = new Button { Text = "Change Text Color" } ;
123
- buttonChangeTextColor . SetBinding ( Button . CommandProperty , " ChangeTextColorCommand" ) ;
134
+ buttonChangeTextColor . SetBinding ( Button . CommandProperty , nameof ( Tab1ViewModel . ChangeTextColorCommand ) ) ;
124
135
tab1Layout . Children . Add ( buttonChangeTextColor ) ;
125
136
126
137
var buttonChangeFontAttributes = new Button { Text = "Change Font Attributes" } ;
127
- buttonChangeFontAttributes . SetBinding ( Button . CommandProperty , " ChangeFontAttributesCommand" ) ;
138
+ buttonChangeFontAttributes . SetBinding ( Button . CommandProperty , nameof ( Tab1ViewModel . ChangeFontAttributesCommand ) ) ;
128
139
tab1Layout . Children . Add ( buttonChangeFontAttributes ) ;
129
140
130
141
var buttonChangePosition = new Button { Text = "Change Position" } ;
131
- buttonChangePosition . SetBinding ( Button . CommandProperty , " ChangePositionCommand" ) ;
142
+ buttonChangePosition . SetBinding ( Button . CommandProperty , nameof ( Tab1ViewModel . ChangePositionCommand ) ) ;
132
143
tab1Layout . Children . Add ( buttonChangePosition ) ;
133
144
134
145
var buttonAddTab = new Button ( ) { Text = "Add tab" } ;
135
146
buttonAddTab . Clicked += ButtonAddTab_Clicked ;
136
- tab1Layout . Children . Add ( buttonAddTab ) ;
137
-
138
-
139
147
var buttonRemoveTab = new Button ( ) { Text = "Remove tab" } ;
140
- buttonRemoveTab . Clicked += ButtonRemoveTab_Clicked ; ;
141
- tab1Layout . Children . Add ( buttonRemoveTab ) ;
148
+ buttonRemoveTab . Clicked += ButtonRemoveTab_Clicked ;
149
+
150
+ grid = new Grid ( ) ;
151
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
152
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
153
+ grid . Children . Add ( buttonAddTab , 0 , 0 ) ;
154
+ grid . Children . Add ( buttonRemoveTab , 1 , 0 ) ;
155
+ tab1Layout . Children . Add ( grid ) ;
156
+
157
+ grid = new Grid { RowSpacing = 0 } ;
158
+ grid . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
159
+ grid . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
160
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
161
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
162
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
163
+ grid . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
164
+
165
+ var leftStepper = new Stepper { Increment = 1 , Minimum = - 50 , Maximum = 50 } ;
166
+ leftStepper . SetBinding ( Stepper . ValueProperty , nameof ( Tab1ViewModel . MarginLeft ) , BindingMode . TwoWay ) ;
167
+ var leftMarginLabel = new Label ( ) ;
168
+ leftMarginLabel . SetBinding ( Label . TextProperty , nameof ( Tab1ViewModel . MarginLeft ) , stringFormat : "Left: {0}" ) ;
169
+ grid . Children . Add ( leftMarginLabel , 0 , 0 ) ;
170
+ grid . Children . Add ( leftStepper , 0 , 1 ) ;
171
+
172
+ var topStepper = new Stepper { Increment = 1 , Minimum = - 50 , Maximum = 50 } ;
173
+ topStepper . SetBinding ( Stepper . ValueProperty , nameof ( Tab1ViewModel . MarginTop ) , BindingMode . TwoWay ) ;
174
+ var topMarginLabel = new Label ( ) ;
175
+ topMarginLabel . SetBinding ( Label . TextProperty , nameof ( Tab1ViewModel . MarginTop ) , stringFormat : "Top: {0}" ) ;
176
+ grid . Children . Add ( topMarginLabel , 1 , 0 ) ;
177
+ grid . Children . Add ( topStepper , 1 , 1 ) ;
178
+
179
+ var rightStepper = new Stepper { Increment = 1 , Minimum = - 50 , Maximum = 50 } ;
180
+ rightStepper . SetBinding ( Stepper . ValueProperty , nameof ( Tab1ViewModel . MarginRight ) , BindingMode . TwoWay ) ;
181
+ var rightMarginLabel = new Label ( ) ;
182
+ rightMarginLabel . SetBinding ( Label . TextProperty , nameof ( Tab1ViewModel . MarginRight ) , stringFormat : "Right: {0}" ) ;
183
+ grid . Children . Add ( rightMarginLabel , 2 , 0 ) ;
184
+ grid . Children . Add ( rightStepper , 2 , 1 ) ;
185
+
186
+ var bottomStepper = new Stepper { Increment = 1 , Minimum = - 50 , Maximum = 50 } ;
187
+ bottomStepper . SetBinding ( Stepper . ValueProperty , nameof ( Tab1ViewModel . MarginBottom ) , BindingMode . TwoWay ) ;
188
+ var bottomMarginLabel = new Label ( ) ;
189
+ bottomMarginLabel . SetBinding ( Label . TextProperty , nameof ( Tab1ViewModel . MarginBottom ) , stringFormat : "Bottom: {0}" ) ;
190
+ grid . Children . Add ( bottomMarginLabel , 3 , 0 ) ;
191
+ grid . Children . Add ( bottomStepper , 3 , 1 ) ;
192
+
193
+ tab1Layout . Children . Add ( grid ) ;
142
194
143
195
var tab1 = new ContentPage
144
196
{
145
197
Title = "Tab1" ,
146
198
Content = tab1Layout
147
199
} ;
148
200
149
- tab1 . SetBinding ( TabBadge . BadgeTextProperty , new Binding ( "Count" ) ) ;
150
- tab1 . SetBinding ( TabBadge . BadgeColorProperty , new Binding ( "BadgeColor" ) ) ;
151
- tab1 . SetBinding ( TabBadge . BadgeTextColorProperty , new Binding ( "BadgeTextColor" ) ) ;
152
- tab1 . SetBinding ( TabBadge . BadgeFontProperty , new Binding ( "BadgeFont" ) ) ;
153
- tab1 . SetBinding ( TabBadge . BadgePositionProperty , new Binding ( "Position" ) ) ;
201
+ tab1 . SetBinding ( TabBadge . BadgeTextProperty , nameof ( Tab1ViewModel . Count ) ) ;
202
+ tab1 . SetBinding ( TabBadge . BadgeColorProperty , nameof ( Tab1ViewModel . BadgeColor ) ) ;
203
+ tab1 . SetBinding ( TabBadge . BadgeTextColorProperty , nameof ( Tab1ViewModel . BadgeTextColor ) ) ;
204
+ tab1 . SetBinding ( TabBadge . BadgeFontProperty , nameof ( Tab1ViewModel . BadgeFont ) ) ;
205
+ tab1 . SetBinding ( TabBadge . BadgePositionProperty , nameof ( Tab1ViewModel . Position ) ) ;
206
+ tab1 . SetBinding ( TabBadge . BadgeMarginProperty , nameof ( Tab1ViewModel . Margin ) ) ;
154
207
155
208
tab1 . BindingContext = new Tab1ViewModel ( ) ;
156
209
return tab1 ;
@@ -205,3 +258,4 @@ protected override void OnResume()
205
258
}
206
259
}
207
260
}
261
+
0 commit comments