【发布时间】:2019-03-08 14:05:35
【问题描述】:
在 Prism Mvvm,Prism.Unity 库中,当我将 DelegateCommand 替换为 Binding Mvvm Command 时。它不工作。这是我的工作代码
public class MainPageViewModel : BindableBase
{
private DelegateCommand _navigationCommand;
private INavigationService _navigationService;
public DelegateCommand NavigateCommand => _navigationCommand ?? (_navigationCommand = new DelegateCommand(ExecuteCommand));
public MainPageViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
}
void ExecuteCommand()
{
_navigationService.NavigateAsync("SecondPage");
}
}
现在我在DeletegateCommand、Command 中进行更改,但不会着火。这是我修改后的代码
public class MainPageViewModel : BindableBase
{
public ICommand _navigationCommand { private set; get; }
private INavigationService _navigationService;
public MainPageViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
_navigationCommand = new Command(() => ExecuteCommand());
}
void ExecuteCommand()
{
_navigationService.NavigateAsync("SecondPage");
}
}
【问题讨论】:
-
使用 Prism.Forms 它是 MVVM 的最佳框架
-
你能给我们指出
Command的实现吗?旁注:你为什么不想使用DelegateCommand? -
@Haukinger - 感谢您的意见。我有错误的命令实现。
标签: c# xamarin mvvm xamarin.forms prism