<TextBox Text="{Binding Mode=OneWay, ElementName=main, Path=MyText1}" /> <TextBox Text="{Binding Mode=TwoWay, ElementName=main, Path=MyText2}" /> <TextBox Text="{Binding Mode=OneWayToSource,ElementName=main, Path=MyText3}" /> <TextBox Text="{Binding Mode=OneTime,ElementName=main, Path=MyText4}" />
Tryby data bindingu :
- OneWay
- TwoWay
- OneWayToSource
- OneTime
Jeśli chodzi o domyślny tryb, to dla większości DependencyProperties jest to OneWay. Wyjątkiem jest np. TextBox.Text, gdzie domyślnie ustawiony jest tryb TwoWay.
Drugą użyteczną opcją, jest UpdateSourceTrigger. Można w ten sposób ustawić, kiedy ma dojść do aktualizacji danych.
<TextBox Text="{Binding Mode=TwoWay, ElementName=main, Path=MyText1, UpdateSourceTrigger=PropertyChanged}" /> <TextBox Text="{Binding Mode=TwoWay, ElementName=main, Path=MyText1, UpdateSourceTrigger=LostFocus}" /> <TextBox Text="{Binding Mode=TwoWay, ElementName=main, Path=MyText1, UpdateSourceTrigger=Explicit}" />
- PropertyChanged
- LostFocus
- Explicit
var bindingExpr = textBox7.GetBindingExpression(TextBox.TextProperty);
bindingExpr.UpdateSource();
Brak komentarzy:
Prześlij komentarz