Skip to content

Commit 2d71fb8

Browse files
Copilotjfversluis
andcommitted
Add clarification about TwoWay binding initialization direction
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
1 parent b0ea8a7 commit 2d71fb8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/fundamentals/data-binding/binding-mode.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ In this example, the <xref:Microsoft.Maui.Controls.Label> is the data-binding so
3636

3737
:::image type="content" source="media/binding-mode/reversebinding.png" alt-text="Reverse binding.":::
3838

39-
In addition, the <xref:Microsoft.Maui.Controls.Slider> continues to work. This is because the default binding mode for the `Value` property of <xref:Microsoft.Maui.Controls.Slider> is `TwoWay`. This means that when the `Value` property is a data-binding target, then the target is set from the source but the source is also set from the target. This allows the <xref:Microsoft.Maui.Controls.Slider> to be set from the initial `Opacity` value.
39+
In addition, the <xref:Microsoft.Maui.Controls.Slider> continues to work. This is because the default binding mode for the `Value` property of <xref:Microsoft.Maui.Controls.Slider> is `TwoWay`. This means that when the `Value` property is a data-binding target, then the target is set from the source but the source is also set from the target. When a `TwoWay` binding is initialized, the target is set from the source first, which allows the <xref:Microsoft.Maui.Controls.Slider> to be set from the initial `Opacity` value.
4040

4141
> [!NOTE]
4242
> Bindable properties don't signal a property change unless the property actually changes. This prevents an infinite loop.
4343
4444
If the default binding mode on the target property is not suitable for a particular data binding, it's possible to override it by setting the `Mode` property of `Binding` (or the `Mode` property of the `Binding` markup extension) to one of the members of the `BindingMode` enumeration:
4545

4646
- `Default`
47-
- `TwoWay` — data goes both ways between source and target
47+
- `TwoWay` — data goes both ways between source and target. When initialized, the target is set from the source first.
4848
- `OneWay` — data goes from source to target
4949
- `OneWayToSource` — data goes from target to source
5050
- `OneTime` — data goes from source to target, but only when the `BindingContext` changes
@@ -63,7 +63,7 @@ Most bindable properties have a default binding mode of `OneWay` but some proper
6363
- `On` property of <xref:Microsoft.Maui.Controls.SwitchCell>
6464
- `Time` property of <xref:Microsoft.Maui.Controls.TimePicker>
6565

66-
These properties are defined as `TwoWay` because when data bindings are used with the Model-View-ViewModel (MVVM) pattern, the viewmodel class is the data-binding source, and the view, which consists of views such as <xref:Microsoft.Maui.Controls.Slider>, are data-binding targets. MVVM bindings resemble the example above, because it's likely that you want each view on the page to be initialized with the value of the corresponding property in the viewmodel, but changes in the view should also affect the viewmodel property.
66+
These properties are defined as `TwoWay` because when data bindings are used with the Model-View-ViewModel (MVVM) pattern, the viewmodel class is the data-binding source, and the view, which consists of views such as <xref:Microsoft.Maui.Controls.Slider>, are data-binding targets. MVVM bindings resemble the example above, because it's likely that you want each view on the page to be initialized with the value of the corresponding property in the viewmodel, but changes in the view should also affect the viewmodel property. When initialized, a `TwoWay` binding sets the target from the source first, and then subsequent changes flow in both directions.
6767

6868
## One-way-to-source bindings
6969

0 commit comments

Comments
 (0)