Skip to content

Commit 31227b1

Browse files
committed
Merged PR 21199: add info about TextBox.Text
add info about TextBox.Text
1 parent 021f9f0 commit 31227b1

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

windows.ui.xaml.data/binding_updatesourcetrigger.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,44 @@ public Windows.UI.Xaml.Data.UpdateSourceTrigger UpdateSourceTrigger { get; set;
1010
# Windows.UI.Xaml.Data.Binding.UpdateSourceTrigger
1111

1212
## -description
13-
Gets or sets a value that determines the timing of binding source updates for two-way bindings.
14-
1513

14+
Gets or sets a value that determines the timing of binding source updates for two-way bindings.
1615

1716
## -xaml-syntax
17+
1818
```xaml
1919
<Binding UpdateSourceTrigger="updateSourceTriggerMemberName"/>
2020
```
21-
22-
2321
## -xaml-values
22+
2423
<dl><dt>updateSourceTriggerMemberName</dt><dd>updateSourceTriggerMemberNameA named constant from the UpdateSourceTrigger enumeration, such as Explicit.</dd>
2524
</dl>
25+
2626
## -property-value
27-
One of the [UpdateSourceTrigger](updatesourcetrigger.md) values. The default is **Default**, which evaluates as a **PropertyChanged** update behavior.
27+
28+
One of the [UpdateSourceTrigger](updatesourcetrigger.md) values. The default is `Default`, which evaluates as a `PropertyChanged` update behavior for most dependency properties, but evaluates as `LostFocus` for the `TextBox.Text` property.
2829

2930
## -remarks
30-
Your other choice for an [UpdateSourceTrigger](updatesourcetrigger.md) behavior is to set the value to be **Explicit**. When a two-way binding has its [UpdateSourceTrigger](updatesourcetrigger.md) value as **Explicit**, you must explicitly call [UpdateSource](bindingexpression_updatesource_190615267.md) on the relevant [BindingExpression](bindingexpression.md) to cause the changed target values to update the data source. Use [GetBindingExpression](../windows.ui.xaml/frameworkelement_getbindingexpression_1210399878.md) to get a [BindingExpression](bindingexpression.md) from an object where a [Binding](binding.md) to a dependency property exists and that binding is a two-way binding with `UpdateSourceTrigger="Explicit"`.
31+
32+
The default behavior for most dependency properties is `PropertyChanged`. However, the default behavior for the [TextBox.Text](../windows.ui.xaml.controls/textbox_text.md) property is `LostFocus`. For a [Binding](binding.md) to `TextBox.Text`, you can change the `UpdateSourceTrigger` like this:
33+
34+
```xaml
35+
<TextBox Text="{x:Bind MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
36+
```
37+
38+
However, it won’t have any effect on a `TextBox` in the control template of another control, such as [NumberBox](/windows/winui/api/microsoft.ui.xaml.controls.numberbox). For example, this `UpdateSourceTrigger` setting has no effect.
39+
40+
```xaml
41+
<!-- This UpdateSourceTrigger setting has no effect. -->
42+
<muxc:NumberBox Text="{x:Bind MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
43+
```
44+
45+
Your other choice for an [UpdateSourceTrigger](updatesourcetrigger.md) behavior is to set the value to be `Explicit`. When a two-way binding has its [UpdateSourceTrigger](updatesourcetrigger.md) value as `Explicit`, you must explicitly call [UpdateSource](bindingexpression_updatesource_190615267.md) on the relevant [BindingExpression](bindingexpression.md) to cause the changed target values to update the data source. Use [GetBindingExpression](../windows.ui.xaml/frameworkelement_getbindingexpression_1210399878.md) to get a [BindingExpression](bindingexpression.md) from an object where a [Binding](binding.md) to a dependency property exists and that binding is a two-way binding with `UpdateSourceTrigger="Explicit"`.
3146

3247
You can't set the property values of a [Binding](binding.md) object after that binding has been attached to a target element and target property. If you attempt this you'll get a run-time exception.
3348

3449
## -examples
3550

3651
## -see-also
52+
3753
[UpdateSource](bindingexpression_updatesource_190615267.md), [Mode](binding_mode.md), [XAML data binding sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlBind), [Data binding in depth](/windows/uwp/data-binding/data-binding-in-depth), [Dependency properties overview](/windows/uwp/xaml-platform/dependency-properties-overview), [GetBindingExpression](../windows.ui.xaml/frameworkelement_getbindingexpression_1210399878.md), [BindingOperations.SetBinding](bindingoperations_setbinding_746099660.md)

windows.ui.xaml.data/updatesourcetrigger.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@ public enum Windows.UI.Xaml.Data.UpdateSourceTrigger : int
1010
# UpdateSourceTrigger
1111

1212
## -description
13-
Defines constants that indicate when a binding source is updated by its binding target in two-way binding.
14-
1513

14+
Defines constants that indicate when a binding source is updated by its binding target in two-way binding.
1615

1716
## -enum-fields
17+
1818
### -field Default:0
19-
Use default behavior from the dependency property that uses the binding. In Windows Runtime, this evaluates the same as a value with **PropertyChanged**.
19+
20+
Use default behavior from the dependency property that uses the binding.
2021

2122
### -field PropertyChanged:1
23+
2224
The binding source is updated whenever the binding target value changes. This is detected automatically by the binding system.
2325

2426
### -field Explicit:2
25-
The binding source is updated only when you call the [BindingExpression.UpdateSource](bindingexpression_updatesource_190615267.md) method.
2627

28+
The binding source is updated only when you call the [BindingExpression.UpdateSource](bindingexpression_updatesource_190615267.md) method. (Not supported for `x:Bind`.)
2729

2830
### -field LostFocus:3
31+
2932
The binding source is updated whenever the binding target element loses focus.
3033

3134
## -remarks
35+
3236
> [!NOTE]
33-
> The default UpdateSourceTrigger value is **Default** rather than **PropertyChanged** for legacy reasons. Previous XAML frameworks enabled a way to register a dependency property with a value that influenced what its default binding update behavior does. That dependency property behavior isn't implemented in the Windows Runtime.
37+
> The default UpdateSourceTrigger value is `Default` rather than `PropertyChanged` for legacy reasons. This evaluates as a `PropertyChanged` update behavior for most dependency properties, but evaluates as `LostFocus` for the `TextBox.Text` property.
3438
3539
### Version history
3640

0 commit comments

Comments
 (0)