【发布时间】:2020-02-19 09:14:42
【问题描述】:
我在 XAML 中有这个 TextBlock,它的 text 属性绑定到 viewmodel 命令。
<TextBlock Text="{Binding SomeText}"></TextBlock>
同时,视图模型看起来像这样:
\\ the text property
private string _someText = "";
public const string SomeTextPropertyName = "SomeText";
public string SomeText
{
get
{
return _someText;
}
set
{
Set(SomeTextPropertyName, ref _someText, value);
}
}
\\ the command that changes the string
private RelayCommand<string> _theCommand;
public RelayCommand<string> TheCommand
{
get
{
return _theCommand
?? (_theCommand = new RelayCommand<string>(ExecuteTheCommand));
}
}
private void ExecuteTheCommand(string somestring)
{
_someText = "Please Change";
\\ MessageBox.Show(SomeText);
}
我可以成功调用TheCommand,就像我使用触发元素中的该命令调用MessageBox 一样。 SomeText 值也会发生变化,如注释的 MessageBox 行中所示。我在这里做错了什么,有什么愚蠢的错误吗?
【问题讨论】:
标签: xaml mvvm mvvm-light