您如何实际实施搜索合同?(C#) [英] How do you actually implement the Search Contract? (C#)

查看:62
本文介绍了您如何实际实施搜索合同?(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解和让搜索合同在我的商店应用中工作时遇到了一些问题.我一直找不到任何类型的文档或指南来解释使用合同的结构.(我已经看过 MSDN 上的快速入门、搜索合同示例和构建视频,但那只是真正涉及 javascript)

I'm having some trouble understanding and getting the search contract to work in my Store app. I have been unable to find any sort of documentation or guide that explains the structure of using the contract. (I've looked at the quickstarts on MSDN, the Search Contract sample and the build video, but that only really deals with javascript)

到目前为止,我已经能够运行查询并将(自定义对象)列表获取到我的搜索合同页面中,然后我尝试将其分配给 defaultviewmodel.results,但无论是什么查询,我都没有输入任何内容在页面上显示 I.还有什么我需要设置的吗?到目前为止,我所拥有的如下(摘录):

So far I've been able to run a query and get a list (of Custom Objects) into my search contract page, and from there I try to assign that to defaultviewmodel.results, but no matter what query I type nothing shows up I on the page. Is there something else I need to set? What I have so far is as follows (excerpts):

App.xaml.cs

App.xaml.cs

protected override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
        {
            SearchCharmResultsPage.Activate(args.QueryText, args.PreviousExecutionState);
            SearchCharmResultsPage.ProcessSearchQuery(args.QueryText);
        }    


public async static void ProcessSearchQuery(string queryString)
        {
            try
            {
                StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("recipeCustomObject                  Debug.WriteLine("Database exists, connecting");
                SQLiteAsyncConnection connection = new SQLiteAsyncConnection("CustomObject_db");
                List<CustomObject> resultsList = new List<CustomObject>();
                string query = "SELECT * FROM CustomObjectDB";
                resultsList =  await connection.QueryAsync<RecipeRecord>(query);  
            }
            catch (FileNotFoundException fnfExc)
            {
                Debug.WriteLine("FNFEXC: " + fnfExc.ToString());
            }
        }

我认为这可能是问题所在,尽管我不确定它是否存在,或者如何改变它.resultsList 列表是在此处创建的,但由于该方法是异步的,我无法从该方法返回.因此,我猜当我尝试在 LoadStateMethod 中分配 this.DefaultViewModel[Results] = resultsList; 时,该对象不存在(认为该程序不会引发错误).当我尝试在 ProcessSearchQuery 方法中添加同一行时,我被告知 this 在静态方法中无效,但我认为我需要该方法静止的?我的问题可能只是一个基本的逻辑错误?

I think it is possible that here lies the problem, though I'm not sure if it is, or how to change it. the resultsList list is created here, but because the method it asynchronous, I can't return from the method. Because of this I'm guess that when I try to assign this.DefaultViewModel[Results] = resultsList; in the LoadStateMethod, the object doesn't exist (thought the program throws no error). When I try to add the same line in the ProcessSearchQuery method, i'm told that this is not valid in a static method, but I think I need the method to be static? My problem might just be a fundamental logic error?

推荐答案

终于搞定了!在这里找到了解决方案:http://jeffblankenburg.com/2012/11/06/31-days-of-windows-8-day-6-search-contract

Finally got it! found the solution here: http://jeffblankenburg.com/2012/11/06/31-days-of-windows-8-day-6-search-contract

对于那些在未来寻找答案的人来说,关键是确保您在 Filter_SelectionChanged 方法中有您的搜索逻辑,这是我没有做的事情.查看以上链接中的指南以了解结构.

For those looking for an answer in the future, the key is to make sure you have your search logic within the Filter_SelectionChanged method, which was something I wasn't doing. Look at the guide within the above link to get an idea of the structure.

这篇关于您如何实际实施搜索合同?(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆