c# - ReactiveUI:如何将“异步”参数传递给 ReactiveCommand.CreateFromTask()
问题描述
我已经定义了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);
没有任何成功和同样的问题..
解决方案
刚刚撞到我的头,看起来是这样的:
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);
}
这只是一个测试...
推荐阅读
- objective-c - Asynchronously Api calls and returning data outside the block
- spring-boot - 使用 Java 1.8 解析所有 ISO 8601 DateTime 格式
- spring-boot - 比较日期的 Spring Boot JPA 规范
- android - Kotlin 编译错误,未解决的参考:旋转和未解决的参考:getSize
- python - 从文本文件中检查密码并将结果打印到单独的文本文件中
- bluetooth - 哪种网状网络(Zigbee、Thread、蓝牙网状网络)网络协议适用于不寻常的用例?
- android - 如何使用 Android P 禁用多点触控?
- android - 更改 SwitchPreference AndroidX 的颜色
- java - 创建线程后创建对象与创建线程时传递对象
- android - 如何禁用 ListAdapter 的动画