c# - Binding update problem -


itemprop = "text">

Binding properties are changing when I have a problem with the binding update See the code given below I have your problem in the following example Will explain

  public class SettingsControl: INotifyPropertyChanged {string _value = "test"; Public Event Threaded ChangedEventHandler Property changed; Protected Zero OnPropertyChanged (string name) {PropertyChangedEventHandler handler = property changed; If (handler! = Null) {handler (new, new property change event event (name)); }} Public SettingsControl () {} public string value {get {return_value; } Set {_value = value; OnPropertyChanged ("value"); }} & Lt; Local: SettingsControl x: key = "settings" & gt; & Lt; / Local: SettingsControl & gt; & Lt; Text box height = "72" text = "{binding value, method = double, source = {settings of static resources}}" /> & Lt; TextBlock Text = "{Binding Value, Mode = One, Source = {Static Resource Settings}}" Vertical Element = "Top" width = "135" /> & Lt; Button height = "100" click = "button 1_Click" />   

and the code behind:

  Private Zero Button 1_Click (Object Sender, RoutedEventArgs e) {SettingsControl settings = New SettingsControl (); Settings.Value = "new value"; }   

Now, when I change the text in textbox , everything works fine and is shown in the new text text block . But if I do not have anything settings.Value , then I set the new text in the code.

I have to do the code to change settings.Value and in the affected TextProperty in TextBlock .

Edit: The solution for those who had the same problem like me:

  Settings: Control Settings = (SettingsControl) Resources ["Settings"]; Settings.Value = "new value";    

Back in your code, you are setting the values ​​on new example , not on the example used.

Try to reverse the code:

  Set the value to Private Zero Button 1_Click (Object Sender, RoutedEventArgs e) {// "This". Value = "new value"; }   

It is being said that, the properties on "control" are usually handled by creating a dependency property, not through INotifyPropertyChanged . This allows them to be set and used correctly in XAML, and participate in bindings more fully in more scenarios.

Comments