6

the TextBlock binding does not work and I cant figure why...

(This Code Works but the TextBlock does not get Updated )

XAML

<TextBlock x:Name="filterAllText"
 Text="{Binding UpdateSourceTrigger=PropertyChanged}" />

Codebehind

filterAllText.DataContext = LogSession.test.MyCoynt;

C#

public class Test : INotifyPropertyChanged {
 public int myCoynt;

     public int MyCoynt {
        get { return myCoynt; }
        set {
            myCoynt = value;
            NotifyPropertyChanged();
        }
    }

     public event PropertyChangedEventHandler PropertyChanged;

     protected virtual void NotifyPropertyChanged(
        [CallerMemberName] String propertyName = "") {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
}
Kapitán Mlíko
  • 4,498
  • 3
  • 43
  • 60
persianLife
  • 1,206
  • 3
  • 17
  • 22

2 Answers2

10

Try this:

<TextBlock x:Name="filterAllText" 
    Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=MyCoynt}" />

And set your DataContext like:

filterAllText.DataContext = LogSession.test;
Kapitán Mlíko
  • 4,498
  • 3
  • 43
  • 60
Goanne
  • 236
  • 2
  • 5
0
<TextBlock x:Name="filterAllText" Text="{Binding Path=., UpdateSourceTrigger=PropertyChanged}" />

this should work but its not the usual way

EDIT: the better way is the anwser from Goanne

Kapitán Mlíko
  • 4,498
  • 3
  • 43
  • 60
blindmeis
  • 22,175
  • 7
  • 55
  • 74