WPF TextBlock text Binding
37,488
Try this:
<TextBlock x:Name="filterAllText"
Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=MyCoynt}" />
And set your DataContext
like:
filterAllText.DataContext = LogSession.test;
Author by
persianLife
Updated on July 19, 2022Comments
-
persianLife almost 2 years
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)); } }
-
blindmeis over 11 years
-
default over 11 yearsoh, I didn't see that he set the
DataContext
to the actual property. Cool trick :)