Mode=TwoWay, UpdateSourceTrigger=PropertyChanged or LostFocus?

前端 未结 1 802
一整个雨季
一整个雨季 2021-01-13 23:41

I bind a table of from a Database into a DataGrid using an Observable Collection:

class ViewModel:INotifyPropertyChanged
{
    private BDDInterneEntities _BD         


        
1条回答
  •  别那么骄傲
    2021-01-14 00:19

    Use of the Binding.UpdateSourceTrigger property is fairly straight forward. It affects when property changes that are made in the UI are reflected in their data bound source objects in the code behind or view models. From the UpdateSourceTrigger Enumeration page on MSDN:

    LostFocus: Updates the binding source whenever the binding target element loses focus.

    PropertyChanged: Updates the binding source immediately whenever the binding target property changes.

    Which one you choose will depend on your requirements. If you want the Bindings and any validation that you may be using to update as the user types each character, then choose the PropertyChanged value. If you want the Bindings and any validation that you may be using to update as the user types tabs away from each control, or otherwise selects a different control, then choose the LostFocus value.

    Now to clarify the use of the Binding.Mode Property, you should be aware of which direction the OneWay and OneWayToSource values work in. From the linked Mode page on MSDN:

    TwoWay updates the target property or the property whenever either the target property or the source property changes.

    OneWay updates the target property only when the source property changes.

    OneTime updates the target property only when the application starts or when the DataContext undergoes a change.

    OneWayToSource updates the source property when the target property changes.

    Default causes the default Mode value of target property to be used.

    To clarify further, the target that is referred to here is the UI control and the source is the data object that is set as the data bound data source.

    0 讨论(0)
提交回复
热议问题