WPF TextBlock text Liaison
TextBlock la liaison ne fonctionne pas et je ne peux pas comprendre pourquoi...
(Ce Code Fonctionne, mais le TextBlock ne sont pas mises à Jour )
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));
}
}
Le
il ne fonctionne pas, je ne pense pas qu'il puisse trouver MyCoynt
Avez-vous mis la Testclass à la
Binding
besoin d'un Path
, j'.e {Binding MyCoynt, UpdateSourceTrigger=PropertyChanged}"
il ne fonctionne pas, je ne pense pas qu'il puisse trouver MyCoynt
Avez-vous mis la Testclass à la
DataContext
?OriginalL'auteur persianLife | 2013-01-31
Vous devez vous connecter pour publier un commentaire.
Essayez ceci:
Et de définir votre
DataContext
comme:OriginalL'auteur Goanne
cela devrait fonctionner mais ce n'est pas la manière habituelle
EDIT: la meilleure façon, c'est la réponse de Goanne
Binding Path=.
? Pourriez-vous expliquer comment cela fonctionne?stackoverflow.com/questions/1066262/...
oh, je n'ai pas vu qu'il a mis la
DataContext
à la propriété réelle. Truc génial 🙂OriginalL'auteur blindmeis