Skip to content

Commit b46d4e8

Browse files
authored
Replace new Binding with compiled bindings (#2747)
* Use compiled bindings. * Fix code bindings.
1 parent 800ff75 commit b46d4e8

File tree

8 files changed

+65
-67
lines changed

8 files changed

+65
-67
lines changed

docs/fundamentals/data-binding/basic-bindings.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ The `BindingContext` property is an important component of data bindings, but it
148148

149149
In this example, the <xref:Microsoft.Maui.Controls.Slider> is defined to control the `Scale` property of the <xref:Microsoft.Maui.Controls.Label>. For that reason, the <xref:Microsoft.Maui.Controls.Slider> is set for a range of -2 to 2.
150150

151-
The code-behind file sets the binding with the `SetBinding` method, with the second argument being a constructor for the `Binding` class:
151+
The code-behind file sets the binding with the `SetBinding` method, with the second argument being a `Func` that gets the value of the `Slider`:
152152

153153
```csharp
154154
public partial class AlternativeCodeBindingPage : ContentPage
@@ -157,13 +157,11 @@ public partial class AlternativeCodeBindingPage : ContentPage
157157
{
158158
InitializeComponent();
159159

160-
label.SetBinding(Label.ScaleProperty, new Binding("Value", source: slider));
160+
label.SetBinding(Label.ScaleProperty, static (Slider s) => s.Value, source: slider);
161161
}
162162
}
163163
```
164164

165-
The `Binding` constructor has 6 parameters, so the `source` parameter is specified with a named argument. The argument is the `slider` object.
166-
167165
> [!NOTE]
168166
> The <xref:Microsoft.Maui.Controls.VisualElement> class also defines `ScaleX` and `ScaleY` properties, which can scale the <xref:Microsoft.Maui.Controls.VisualElement> differently in the horizontal and vertical directions.
169167

docs/fundamentals/data-binding/multibinding.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ public class MultiBindingConverterCodePage : ContentPage
159159
{
160160
Bindings = new Collection<BindingBase>
161161
{
162-
new Binding("Employee1.IsOver16"),
163-
new Binding("Employee1.HasPassedTest"),
164-
new Binding("Employee1.IsSuspended", converter: new InverterConverter())
162+
Binding.Create(static (GroupViewModel vm) => vm.Employee1.IsOver16),
163+
Binding.Create(static (GroupViewModel vm) => vm.Employee1.HasPassedTest),
164+
Binding.Create(static (GroupViewModel vm) => vm.Employee1.IsSuspended, converter: new InverterConverter())
165165
},
166166
Converter = new AllTrueMultiConverter()
167-
});
167+
});
168168

169169
Title = "MultiBinding converter demo";
170170
Content = checkBox;
@@ -201,9 +201,9 @@ label.SetBinding(Label.TextProperty, new MultiBinding
201201
{
202202
Bindings = new Collection<BindingBase>
203203
{
204-
new Binding("Employee1.Forename"),
205-
new Binding("Employee1.MiddleName"),
206-
new Binding("Employee1.Surname")
204+
Binding.Create(static (GroupViewModel vm) => vm.Employee1.Forename),
205+
Binding.Create(static (GroupViewModel vm) => vm.Employee1.MiddleName),
206+
Binding.Create(static (GroupViewModel vm) => vm.Employee1.Surname)
207207
},
208208
StringFormat = "{0} {1} {2}"
209209
});

docs/platform-integration/snippets/shared_1/MediaPage.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public MediaPage()
1717
this.BindingContext = this;
1818

1919
var imageControl = new Image();
20-
imageControl.SetBinding(Image.SourceProperty, new Binding("ImageItem"));
20+
imageControl.SetBinding(Image.SourceProperty, Binding.Create(static (ImageItem item) => item.ImageItem));
2121

2222
Content = new VerticalStackLayout
2323
{
@@ -105,15 +105,15 @@ public void CancelSpeech()
105105
{
106106
if (cts?.IsCancellationRequested ?? true)
107107
return;
108-
108+
109109
cts.Cancel();
110110
}
111111
//</speak_cancel>
112112

113113

114114
//<speak_queue>
115115
bool isBusy = false;
116-
116+
117117
public void SpeakMultiple()
118118
{
119119
isBusy = true;
@@ -125,4 +125,4 @@ public void SpeakMultiple()
125125
.ContinueWith((t) => { isBusy = false; }, TaskScheduler.FromCurrentSynchronizationContext());
126126
}
127127
//</speak_queue>
128-
}
128+
}

docs/user-interface/controls/carouselview/interaction.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The equivalent C# code is:
5555

5656
```csharp
5757
CarouselView carouselView = new CarouselView();
58-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
58+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
5959
carouselView.CurrentItemChanged += OnCurrentItemChanged;
6060
```
6161

@@ -89,9 +89,9 @@ The equivalent C# code is:
8989

9090
```csharp
9191
CarouselView carouselView = new CarouselView();
92-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
93-
carouselView.SetBinding(CarouselView.CurrentItemChangedCommandProperty, "ItemChangedCommand");
94-
carouselView.SetBinding(CarouselView.CurrentItemChangedCommandParameterProperty, new Binding("CurrentItem", source: RelativeBindingSource.Self));
92+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
93+
carouselView.SetBinding(CarouselView.CurrentItemChangedCommandProperty, static (MonkeysViewModel vm) => vm.ItemChangedCommand);
94+
carouselView.SetBinding(CarouselView.CurrentItemChangedCommandParameterProperty, Binding.Create(static (CarouselView cv) => cv.CurrentItem, source: RelativeBindingSource.Self));
9595
```
9696

9797
In this example, the `CurrentItemChangedCommand` property binds to the `ItemChangedCommand` property, passing the `CurrentItem` property value to it as an argument. The `ItemChangedCommand` can then respond to the current item changing, as required:
@@ -128,7 +128,7 @@ The equivalent C# code is:
128128

129129
```csharp
130130
CarouselView carouselView = new CarouselView();
131-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
131+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
132132
carouselView.PositionChanged += OnPositionChanged;
133133
```
134134

@@ -162,9 +162,9 @@ The equivalent C# code is:
162162

163163
```csharp
164164
CarouselView carouselView = new CarouselView();
165-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
166-
carouselView.SetBinding(CarouselView.PositionChangedCommandProperty, "PositionChangedCommand");
167-
carouselView.SetBinding(CarouselView.PositionChangedCommandParameterProperty, new Binding("Position", source: RelativeBindingSource.Self));
165+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
166+
carouselView.SetBinding(CarouselView.PositionChangedCommandProperty, static (MonkeysViewModel vm) => vm.PositionChangedCommand);
167+
carouselView.SetBinding(CarouselView.PositionChangedCommandParameterProperty, Binding.Create(static (CarouselView cv) => cv.Position, source: RelativeBindingSource.Self));
168168
```
169169

170170
In this example, the `PositionChangedCommand` property binds to the `PositionChangedCommand` property, passing the `Position` property value to it as an argument. The `PositionChangedCommand` can then respond to the position changing, as required:
@@ -194,8 +194,8 @@ The equivalent C# code is:
194194

195195
```csharp
196196
CarouselView carouselView = new CarouselView();
197-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
198-
carouselView.SetBinding(CarouselView.CurrentItemProperty, "CurrentItem");
197+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
198+
carouselView.SetBinding(CarouselView.CurrentItemProperty, static (MonkeysViewModel vm) => vm.CurrentItem);
199199
```
200200

201201
> [!NOTE]
@@ -239,8 +239,8 @@ The equivalent C# code is:
239239

240240
```csharp
241241
CarouselView carouselView = new CarouselView();
242-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
243-
carouselView.SetBinding(CarouselView.PositionProperty, "Position");
242+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
243+
carouselView.SetBinding(CarouselView.PositionProperty, static (MonkeysViewModel vm) => vm.Position);
244244
```
245245

246246
> [!NOTE]

docs/user-interface/controls/carouselview/populate-data.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The equivalent C# code is:
3636

3737
```csharp
3838
CarouselView carouselView = new CarouselView();
39-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
39+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
4040
```
4141

4242
In this example, the `ItemsSource` property data binds to the `Monkeys` property of the connected viewmodel.
@@ -92,21 +92,21 @@ The equivalent C# code is:
9292

9393
```csharp
9494
CarouselView carouselView = new CarouselView();
95-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
95+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
9696

9797
carouselView.ItemTemplate = new DataTemplate(() =>
9898
{
9999
Label nameLabel = new Label { ... };
100-
nameLabel.SetBinding(Label.TextProperty, "Name");
100+
nameLabel.SetBinding(Label.TextProperty, static (Monkey monkey) => monkey.Name);
101101

102102
Image image = new Image { ... };
103-
image.SetBinding(Image.SourceProperty, "ImageUrl");
103+
image.SetBinding(Image.SourceProperty, static (Monkey monkey) => monkey.ImageUrl);
104104

105105
Label locationLabel = new Label { ... };
106-
locationLabel.SetBinding(Label.TextProperty, "Location");
106+
locationLabel.SetBinding(Label.TextProperty, static (Monkey monkey) => monkey.Location);
107107

108108
Label detailsLabel = new Label { ... };
109-
detailsLabel.SetBinding(Label.TextProperty, "Details");
109+
detailsLabel.SetBinding(Label.TextProperty, static (Monkey monkey) => monkey.Details);
110110

111111
StackLayout stackLayout = new StackLayout();
112112
stackLayout.Add(nameLabel);
@@ -174,7 +174,7 @@ CarouselView carouselView = new CarouselView
174174
{
175175
ItemTemplate = new MonkeyDataTemplateSelector { ... }
176176
};
177-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
177+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
178178
```
179179

180180
The `ItemTemplate` property is set to a `MonkeyDataTemplateSelector` object. The following example shows the `MonkeyDataTemplateSelector` class:
@@ -280,7 +280,7 @@ The equivalent C# code is:
280280

281281
```csharp
282282
CarouselView carouselView = new CarouselView();
283-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
283+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
284284

285285
carouselView.ItemTemplate = new DataTemplate(() =>
286286
{
@@ -294,17 +294,17 @@ carouselView.ItemTemplate = new DataTemplate(() =>
294294
IconImageSource = "favorite.png",
295295
BackgroundColor = Colors.LightGreen
296296
};
297-
favoriteSwipeItem.SetBinding(MenuItem.CommandProperty, new Binding("BindingContext.FavoriteCommand", source: carouselView));
298-
favoriteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, ".");
297+
favoriteSwipeItem.SetBinding(MenuItem.CommandProperty, Binding.Create(static (MonkeysViewModel vm) => vm.FavoriteCommand, source: carouselView.BindingContext);
298+
favoriteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, static (CarouselView cv) => cv.CurrentItem, source: carouselView);
299299

300300
SwipeItem deleteSwipeItem = new SwipeItem
301301
{
302302
Text = "Delete",
303303
IconImageSource = "delete.png",
304304
BackgroundColor = Colors.LightPink
305305
};
306-
deleteSwipeItem.SetBinding(MenuItem.CommandProperty, new Binding("BindingContext.DeleteCommand", source: carouselView));
307-
deleteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, ".");
306+
deleteSwipeItem.SetBinding(MenuItem.CommandProperty, Binding.Create(static (MonkeysViewModel vm) => vm.DeleteCommand, source: carouselView.BindingContext);
307+
deleteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, static (CarouselView cv) => cv.CurrentItem, source: carouselView);
308308

309309
swipeView.TopItems = new SwipeItems { favoriteSwipeItem };
310310
swipeView.BottomItems = new SwipeItems { deleteSwipeItem };
@@ -353,7 +353,7 @@ ICommand refreshCommand = new Command(() =>
353353
refreshView.Command = refreshCommand;
354354

355355
CarouselView carouselView = new CarouselView();
356-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Animals");
356+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (AnimalsViewModel vm) => vm.Animals);
357357
refreshView.Content = carouselView;
358358
// ...
359359
```
@@ -402,7 +402,7 @@ CarouselView carouselView = new CarouselView
402402
RemainingItemsThreshold = 2
403403
};
404404
carouselView.RemainingItemsThresholdReached += OnCollectionViewRemainingItemsThresholdReached;
405-
carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Animals");
405+
carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (AnimalsViewModel vm) => vm.Animals);
406406
```
407407

408408
In this code example, the `RemainingItemsThresholdReached` event fires when there are 2 items not yet scrolled to, and in response executes the `OnCollectionViewRemainingItemsThresholdReached` event handler:

docs/user-interface/controls/collectionview/populate-data.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The equivalent C# code is:
3636

3737
```csharp
3838
CollectionView collectionView = new CollectionView();
39-
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
39+
collectionView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
4040
```
4141

4242
In this example, the `ItemsSource` property data binds to the `Monkeys` property of the connected viewmodel.
@@ -90,7 +90,7 @@ The equivalent C# code is:
9090

9191
```csharp
9292
CollectionView collectionView = new CollectionView();
93-
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
93+
collectionView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
9494

9595
collectionView.ItemTemplate = new DataTemplate(() =>
9696
{
@@ -101,13 +101,13 @@ collectionView.ItemTemplate = new DataTemplate(() =>
101101
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
102102

103103
Image image = new Image { Aspect = Aspect.AspectFill, HeightRequest = 60, WidthRequest = 60 };
104-
image.SetBinding(Image.SourceProperty, "ImageUrl");
104+
image.SetBinding(Image.SourceProperty, static (Monkey monkey) => monkey.ImageUrl);
105105

106106
Label nameLabel = new Label { FontAttributes = FontAttributes.Bold };
107-
nameLabel.SetBinding(Label.TextProperty, "Name");
107+
nameLabel.SetBinding(Label.TextProperty, static (Monkey monkey) => monkey.Name);
108108

109109
Label locationLabel = new Label { FontAttributes = FontAttributes.Italic, VerticalOptions = LayoutOptions.End };
110-
locationLabel.SetBinding(Label.TextProperty, "Location");
110+
locationLabel.SetBinding(Label.TextProperty, static (Monkey monkey) => monkey.Location);
111111

112112
Grid.SetRowSpan(image, 2);
113113

@@ -172,7 +172,7 @@ CollectionView collectionView = new CollectionView
172172
{
173173
ItemTemplate = new MonkeyDataTemplateSelector { ... }
174174
};
175-
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
175+
collectionView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
176176
```
177177

178178
The `ItemTemplate` property is set to a `MonkeyDataTemplateSelector` object. The following example shows the `MonkeyDataTemplateSelector` class:
@@ -237,7 +237,7 @@ The equivalent C# code is:
237237

238238
```csharp
239239
CollectionView collectionView = new CollectionView();
240-
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys");
240+
collectionView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
241241

242242
collectionView.ItemTemplate = new DataTemplate(() =>
243243
{
@@ -252,17 +252,17 @@ collectionView.ItemTemplate = new DataTemplate(() =>
252252
IconImageSource = "favorite.png",
253253
BackgroundColor = Colors.LightGreen
254254
};
255-
favoriteSwipeItem.SetBinding(MenuItem.CommandProperty, new Binding("BindingContext.FavoriteCommand", source: collectionView));
256-
favoriteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, ".");
255+
favoriteSwipeItem.SetBinding(MenuItem.CommandProperty, Binding.Create(static (MonkeysViewModel vm) => vm.FavoriteCommand, source: collectionView.BindingContext);
256+
favoriteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, static (CollectionView cv) => cv.SelectedItem, source: collectionView);
257257

258258
SwipeItem deleteSwipeItem = new SwipeItem
259259
{
260260
Text = "Delete",
261261
IconImageSource = "delete.png",
262262
BackgroundColor = Colors.LightPink
263263
};
264-
deleteSwipeItem.SetBinding(MenuItem.CommandProperty, new Binding("BindingContext.DeleteCommand", source: collectionView));
265-
deleteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, ".");
264+
deleteSwipeItem.SetBinding(MenuItem.CommandProperty, Binding.Create(static (MonkeysViewModel vm) => vm.DeleteCommand, source: collectionView.BindingContext);
265+
deleteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, static (CollectionView cv) => cv.SelectedItem, source: collectionView);
266266

267267
swipeView.LeftItems = new SwipeItems { favoriteSwipeItem, deleteSwipeItem };
268268
swipeView.Content = grid;
@@ -304,7 +304,7 @@ ICommand refreshCommand = new Command(() =>
304304
refreshView.Command = refreshCommand;
305305

306306
CollectionView collectionView = new CollectionView();
307-
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Animals");
307+
collectionView.SetBinding(ItemsView.ItemsSourceProperty, static (AnimalsViewModel vm) => vm.Animals);
308308
refreshView.Content = collectionView;
309309
// ...
310310
```
@@ -355,7 +355,7 @@ CollectionView collectionView = new CollectionView
355355
RemainingItemsThreshold = 5
356356
};
357357
collectionView.RemainingItemsThresholdReached += OnCollectionViewRemainingItemsThresholdReached;
358-
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Animals");
358+
collectionView.SetBinding(ItemsView.ItemsSourceProperty, static (AnimalsViewModel vm) => vm.Animals);
359359
```
360360

361361
In this code example, the `RemainingItemsThresholdReached` event fires when there are 5 items not yet scrolled to, and in response executes the `OnCollectionViewRemainingItemsThresholdReached` event handler:

docs/user-interface/controls/picker.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ The equivalent C# code is:
102102

103103
```csharp
104104
Label monkeyNameLabel = new Label();
105-
monkeyNameLabel.SetBinding(Label.TextProperty, new Binding("SelectedItem", source: picker));
105+
monkeyNameLabel.SetBinding(Label.TextProperty, Binding.Create(static (Picker picker) => picker.SelectedItem, source: picker));
106106
```
107107

108108
In addition, an event handler can be executed when the `SelectedIndexChanged` event fires:
@@ -139,8 +139,8 @@ The equivalent C# code is shown below:
139139

140140
```csharp
141141
Picker picker = new Picker { Title = "Select a monkey" };
142-
picker.SetBinding(Picker.ItemsSourceProperty, "Monkeys");
143-
picker.ItemDisplayBinding = new Binding("Name");
142+
picker.SetBinding(Picker.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
143+
picker.ItemDisplayBinding = Binding.Create(static (Monkey monkey) => monkey.Name);
144144
```
145145

146146
In this example, the `ItemsSource` property data binds to the `Monkeys` property of the binding context, which returns an `IList<Monkey>` collection. The following code example shows the `Monkey` class, which contains four properties:
@@ -176,21 +176,21 @@ The equivalent C# code is:
176176

177177
```csharp
178178
Picker picker = new Picker { Title = "Select a monkey" };
179-
picker.SetBinding(Picker.ItemsSourceProperty, "Monkeys");
180-
picker.SetBinding(Picker.SelectedItemProperty, "SelectedMonkey");
181-
picker.ItemDisplayBinding = new Binding("Name");
179+
picker.SetBinding(Picker.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys);
180+
picker.SetBinding(Picker.SelectedItemProperty, static (MonkeysViewModel vm) => vm.SelectedMonkey);
181+
picker.ItemDisplayBinding = Binding.Create(static (Monkey monkey) => monkey.Name);
182182

183183
Label nameLabel = new Label { ... };
184-
nameLabel.SetBinding(Label.TextProperty, "SelectedMonkey.Name");
184+
nameLabel.SetBinding(Label.TextProperty, static (MonkeysViewModel vm) => vm.SelectedMonkey.Name);
185185

186186
Label locationLabel = new Label { ... };
187-
locationLabel.SetBinding(Label.TextProperty, "SelectedMonkey.Location");
187+
locationLabel.SetBinding(Label.TextProperty, static (MonkeysViewModel vm) => vm.SelectedMonkey.Location);
188188

189189
Image image = new Image { ... };
190-
image.SetBinding(Image.SourceProperty, "SelectedMonkey.ImageUrl");
190+
image.SetBinding(Image.SourceProperty, static (MonkeysViewModel vm) => vm.SelectedMonkey.ImageUrl);
191191

192192
Label detailsLabel = new Label();
193-
detailsLabel.SetBinding(Label.TextProperty, "SelectedMonkey.Details");
193+
detailsLabel.SetBinding(Label.TextProperty, static (MonkeysViewModel vm) => vm.SelectedMonkey.Details);
194194
```
195195

196196
The `SelectedItem` property data binds to the `SelectedMonkey` property of the binding context, which is of type `Monkey`. Therefore, when the user selects an item in the <xref:Microsoft.Maui.Controls.Picker>, the `SelectedMonkey` property will be set to the selected `Monkey` object. The `SelectedMonkey` object data is displayed in the user interface by <xref:Microsoft.Maui.Controls.Label> and <xref:Microsoft.Maui.Controls.Image> views.

0 commit comments

Comments
 (0)