简体   繁体   中英

Xaml Binding in Windows Phone 7.1

I have a problem with my xaml and binding in windows phone 7. I have a listbox and it's itemSource is sent in the code-behind. The ItemsSource is a class that has several variables that are bound in my xaml and everything works flawlessly on startup. The problem is everythime I want to change a value of a property that is bound for example: <TextBox Name="x" Text="{Binding Path=Name}" /> when I change this in the code-behind x.Text = "Name" All the bindings for the text of the textbox 'x' which is a listboxitem are blocked and can never be changed all of the items in the listbox are now set with the string 'Name'. I have the INotifyPropertyChanged added to my class and that does not resolve this issue. Please help.

Setting a bound property clears the data binding (for one way binding). I have never seen any Microsoft documentation on this but I have experienced it many times in my code and have come to accept it.

It makes sense if you think about it, since changing the property value means the property no longer reflects the value in the bound data.

The value of the bound property can be changed, although is not a good practice. This works only for TwoWay binding, so your code should look like this <TextBox Name="x" Text="{Binding Path=Name, Mode=TwoWay}" /> . Documentation can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM