我已经这样定义ReactiveCommand
:
CmdGetTestResult = ReactiveCommand.CreateFromTask<bool>(async detailed =>
{
var result = await Client.FooAsync(detailed);
});
CmdGetTestResult.ToPropertyEx(this, x => x.GetTestResultResponse);
viewmodel
public bool Detailed { get; set; }
public Unit GetTestResultResponse { [ObservableAsProperty]get; }
public ReactiveCommand<bool, Unit> CmdGetTestResult { get; }
在xaml
中:
<Button
Content="get test result (F4)"
Command="{Binding Path=ViewModel.CmdGetTestResult}"
CommandParameter="{Binding Path=ViewModel.Detailed}"/>
属性detailed
是true
(已在调试器中检查),但始终以false
的形式传递。我的代码搞什么了?
编辑:
我也尝试了reactiveui
的方式:
this.BindCommand(ViewModel, model => model.CmdGetTestResult, window => window.ButtonGetTestResult, model => model.Detailed);
没有成功和同样的问题。
答案 0 :(得分:0)
只是撞了撞我的头,看起来像是这样:
private readonly ObservableAsPropertyHelper<List<LocationData>> _locations;
public ReactiveCommand<LocationData, List<LocationData>> GetLocations { get; }
public ViewModel
{
GetLocations = ReactiveCommand.CreateFromTask<LocationData, List<LocationData>>(GetLocationsTask);
}
private async Task<List<LocationData>> GetLocationsTask(LocationData i)
{
return await LocationService.GetLocationsAsync(i);
}
这只是一个测试员...