我正在更改类构造函数中的标签,它工作正常,标签更新(“0”)。我也在尝试更新标签,当我点击一个按钮,但它不工作(“X”)。我注意到调试标签值已更新,PropertyChanged被触发,但视图不会更改。PropertyChanged被触发,但视图未更新
public class HomeViewModel : ViewModelBase
{
string playerA;
public string PlayerA
{
get
{
return playerA;
}
set
{
playerA = value;
this.Notify("playerA");
}
}
public ICommand PlayerA_Plus_Command
{
get;
set;
}
public HomeViewModel()
{
this.PlayerA_Plus_Command = new Command(this.PlayerA_Plus);
this.PlayerA = "0";
}
public void PlayerA_Plus()
{
this.PlayerA = "X";
}
}
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void Notify(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
在这里写下你的xaml。我的意思是按钮和标签+将[string platerA;]更改为[string playerA =“!”;]如果您的标签不显示!毕竟,你的绑定有一个问题。 –