我需要在点击按钮时更改标签值,这样它就会说"请等待"。
该按钮有一个命令,但由于命令不知道窗口控件,我无法从命令中引用它们。
作为参考,这是标签:
<Label Content="{Binding EuroCurrentRate}" Margin="450,226,672,351" x:Name="EurLabel" Foreground="White" FontSize="22" >
这个命令:
class EuroClickCommand : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
var viewModel = (RTViewModel)parameter;
viewModel.OpenGraph();// When button is pushed fire this function
}
}
ViewModel中的属性:
public ICommand ButtonClickCommand
{
get
{
return new EuroClickCommand();
}
}
public void OpenGraph()//Fire commands by button binding and command mechanism
{
AreaChart.MainWindow myWindow = new AreaChart.MainWindow();
myWindow.Show();
}
如何更改命令中的标签内容?
答案 0 :(得分:0)
Label已绑定到viewmodel属性:
<Label Content="{Binding EuroCurrentRate}" .../>
在命令方法中更改该属性:
public void Execute(object parameter)
{
var viewModel = (RTViewModel)parameter;
viewModel.EuroCurrentRate = "Please wait";
viewModel.OpenGraph();// When button is pushed fire this function
}
或更可能EuroCurrentRate = "Please wait";
应该在OpenGraph()方法