我正在更改類構造函數中的標籤,它工作正常,標籤更新(「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 =「!」;]如果您的標籤不顯示!畢竟,你的綁定有一個問題。 –