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)); } } 
3
  • 2
    The Binding needs a Path, i.e {Binding MyCoynt, UpdateSourceTrigger=PropertyChanged}" Commented Jan 31, 2013 at 11:16
  • it does not work, I dont think that it can find MyCoynt Commented Jan 31, 2013 at 11:19
  • Have you set the Testclass to be the DataContext? Commented Jan 31, 2013 at 11:22

2 Answers 2

10

Try this:

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

And set your DataContext like:

filterAllText.DataContext = LogSession.test; 
Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

oh, I didn't see that he set the DataContext to the actual property. Cool trick :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.