首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DelegateCommand异步支持棱镜4.1

DelegateCommand异步支持棱镜4.1
EN

Stack Overflow用户
提问于 2014-07-29 01:43:31
回答 1查看 939关注 0票数 1

当我使用DelegateCommand进行绑定时,我在代码中看到了错误。在其方法中,我调用了1 asyc服务,该服务调用arcgis服务器来使用Task Service查找城市名称。

我为Prism 4.1异步支持而烦恼?如果没有,有没有其他的解决办法?

代码语言:javascript
复制
 public  DelegateCommand SearchCitiesCommand;
    private PlaceFinderService placeFinderService;

    public GenericMapViewModel()
    {
        HelloMapMessage = "Generic Map Pow Pow !!";
        placeFinderService = new PlaceFinderService();
        SearchCitiesCommand = DelegateCommand. //new DelegateCommand(Search);
    }

    public virtual async Task Search()
    {
        List<Graphic> graphics=await placeFinderService.FindAsync(SearchText);
        SearchResults = graphics;
    }

ASYN服务

代码语言:javascript
复制
public class PlaceFinderService
{
    TaskCompletionSource<List<Graphic>> tcs;
    public Task<List<Graphic>> FindAsync(String searchText)
    {
        FindParameters findParams = new FindParameters();
        findParams.LayerIds.AddRange(new int[] { 0 }); // cities layer
        findParams.SearchFields.AddRange(new string[] { "CITY_NAME" });
        findParams.SpatialReference = new SpatialReference(4326);
        findParams.SearchText = searchText;
        FindTask findTask = new FindTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer");
        tcs = new TaskCompletionSource<List<Graphic>>();
        findTask.ExecuteCompleted += FindTaskExecuteCompleted;
        findTask.Failed += findTaskFailed;
        return tcs.Task;
    }

    private void findTaskFailed(object sender, TaskFailedEventArgs e)
    {
        tcs.TrySetResult(new List<Graphic>());
    }

    private void FindTaskExecuteCompleted(object sender, FindEventArgs e)
    {
        List<Graphic> graphics = new List<Graphic>();
        foreach (var result in e.FindResults)
        {
            graphics.Add(result.Feature);
        }
        tcs.TrySetResult(graphics);

    }
}

我很少看到http://prismwindowsruntime.codeplex.com/discussions/535816,但我认为它是棱镜5。

EN

回答 1

Stack Overflow用户

发布于 2014-07-29 01:50:20

据我所知,没有MVVM框架支持“异步命令”。IMO,这是因为有很多不同的语义可能性。

我有一个MSDN article,你可能会发现它对你有帮助。它提供了一些想法(和示例实现),但归根结底,您必须制作自己的"AsyncCommand“,因为确切的语义将取决于应用程序的需求。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25001089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档