【发布时间】:2018-05-31 18:21:32
【问题描述】:
我有一个使用 MVVM Light nuget 的 RelayCommand 的简单代码,但无法正常工作,只想按一个按钮并显示一条消息,
我的 xaml 代码:
<StackLayout
Padding="8">
<Button
Command="{Binding ConvertCommand}"
Text="Hello">
</Button>
</StackLayout>
我的视图模型:
public class MainViewModel
{
public ICommand ConvertCommand { get { return new RelayCommand(ConvertMoney); } }
public async void ConvertMoney()
{
await App.Current.MainPage.DisplayAlert("hello", "hello", "acept");
return;
}
}
【问题讨论】:
-
您是否设置了视图的绑定上下文?也不要将 async 与 void 一起使用,而是使用 Task。
-
绑定工作正常,使用Command代替RelayCommand效果很好,谢谢你的cmets!!!