Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF TextBlock text Binding

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));
        }
}
like image 733
persianLife Avatar asked Jan 31 '13 11:01

persianLife


1 Answers

Try this:

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

And set your DataContext like:

filterAllText.DataContext = LogSession.test;
like image 60
Goanne Avatar answered Sep 30 '22 16:09

Goanne