c#.net网格应用程序搜索页面

c#.net网格应用程序搜索页面,c#,.net,search,windows-store-apps,C#,.net,Search,Windows Store Apps,正在尝试使用来自的指南 我的应用程序包含私人教练,私人教练有自己的客户。 我希望能够搜索客户 这就是我的能力:我可以在first/lastname上搜索客户,它会显示有多少个结果,即结果(3),但不会显示它们 我已经包括了我的数据: using PersonalTrainerGridApp.Data; navigationHelper\u LoadState中的if语句让我感到困惑,我不确定其中包含什么,也不确定选中的过滤器是否正确 有人有什么建议吗?谢谢格式化 private async v

正在尝试使用来自的指南

我的应用程序包含私人教练,私人教练有自己的客户。 我希望能够搜索客户

这就是我的能力:我可以在first/lastname上搜索客户,它会显示有多少个结果,即结果(3),但不会显示它们

我已经包括了我的数据:

using PersonalTrainerGridApp.Data;
navigationHelper\u LoadState
中的
if
语句让我感到困惑,我不确定其中包含什么,也不确定选中的
过滤器是否正确

有人有什么建议吗?谢谢格式化

private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        var queryText = e.NavigationParameter as String;
        // Initialize the results list.
        AllResultsCollection = new Dictionary<string, IEnumerable<SampleDataSource>>();

        // Keep track of the number of matching items. 
        var totalMatchingItems = 0;
        var filterList = new List<Filter>();
        var groups = await SampleDataSource.GetPersonalTrainerAsync();

        foreach (var group in groups)
        {
            var matchingItems = group.Customers.Where(
                item => 
                    item.FirstName.IndexOf(
                        queryText, StringComparison.CurrentCultureIgnoreCase) > -1 || item.LastName.IndexOf(
                        queryText, StringComparison.CurrentCultureIgnoreCase) > -1 );

            int numberOfMatchingItems = matchingItems.Count();
            totalMatchingItems += numberOfMatchingItems;
            if (numberOfMatchingItems > 0)
            {
                AllResultsCollection.Add(group.Customers, matchingItems);
                filterList.Add(new Filter(group.Customers, numberOfMatchingItems));
            }

        }

        // Create an entry for "All" for viewing all search results. 
        filterList.Insert(0, new Filter("All", totalMatchingItems, true));

        // Communicate results through the view model
        this.DefaultViewModel["QueryText"] = '\"' + queryText + '\"';
        this.DefaultViewModel["Filters"] = filterList;
        this.DefaultViewModel["ShowFilters"] = true;

    }

    /// <summary>
    /// Invoked when a filter is selected using a RadioButton when not snapped.
    /// </summary>
    /// <param name="sender">The selected RadioButton instance.</param>
    /// <param name="e">Event data describing how the RadioButton was selected.</param>
    void Filter_Checked(object sender, RoutedEventArgs e)
    {
        // Retrieve the data context of the sender (the selected radio button).
        // This gives us the selected Filter object. 
        var filter = (sender as FrameworkElement).DataContext as Filter;

        // Mirror the change into the CollectionViewSource.
        // This is most likely not needed.
        if (filtersViewSource.View != null)
        {
            filtersViewSource.View.MoveCurrentTo(filter);
        }

        // Determine which filter was selected
        if (filter != null)
        {
            // Mirror the results into the corresponding Filter object to allow the
            // RadioButton representation used when not snapped to reflect the change
            filter.Active = true;

            // TODO: Respond to the change in active filter by setting this.DefaultViewModel["Results"]
            //       to a collection of items with bindable Image, Title, Subtitle, and Description properties

            if (filter.Name.Equals("All"))
            {
                var tempResults = new List<SampleDataSource>();

                // Add the items from each group to the temporary results
                // list. 
                foreach (var group in AllResultsCollection)
                {
                    tempResults.AddRange(group.Value);

                }

                // Display the items.
                this.DefaultViewModel["Results"] = tempResults;
            }
            else if (AllResultsCollection.ContainsKey(filter.Name))
            {
                this.DefaultViewModel["Results"] =
                  new List<SampleDataSource>(AllResultsCollection[filter.Name]);
            }

            // Ensure results are found
            object results;
            ICollection resultsCollection;
            if (this.DefaultViewModel.TryGetValue("Results", out results) &&
                (resultsCollection = results as ICollection) != null &&
                resultsCollection.Count != 0)
            {
                VisualStateManager.GoToState(this, "ResultsFound", true);
                return;
            }
        }

        // Display informational text when there are no search results.
        VisualStateManager.GoToState(this, "NoResultsFound", true);
    }
private async void navigationHelper\u LoadState(对象发送方,LoadStateEventArgs e)
{
var queryText=e.NavigationParameter作为字符串;
//初始化结果列表。
AllResultCollection=new Dictionary();
//跟踪匹配项目的数量。
var totalMatchingItems=0;
var filterList=新列表();
var groups=await SampleDataSource.GetPersonalTrainerAsync();
foreach(组中的var组)
{
var matchingItems=group.Customers.Where(
项目=>
item.FirstName.IndexOf(
queryText,StringComparison.CurrentCultureInoRecase)>-1 | | item.LastName.IndexOf(
queryText,StringComparison.CurrentCultureInoRecase)>-1);
int numberOfMatchingItems=matchingItems.Count();
totalMatchingItems+=MatchingItems的数量;
如果(numberOfMatchingItems>0)
{
AllResultCollection.Add(group.Customers,matchingItems);
添加(新过滤器(group.Customers,numberOfMatchingItems));
}
}
//为“全部”创建一个条目以查看所有搜索结果。
插入(0,新过滤器(“全部”,totalMatchingItems,true));
//通过视图模型传达结果
这个.DefaultViewModel[“QueryText”]=“\”+QueryText+“\”;
this.DefaultViewModel[“Filters”]=filterList;
this.DefaultViewModel[“ShowFilters”]=true;
}
/// 
///在未捕捉时使用单选按钮选择过滤器时调用。
/// 
///选定的RadioButton实例。
///描述如何选择RadioButton的事件数据。
已选中无效过滤器(对象发送器,路由目标e)
{
//检索发件人的数据上下文(所选单选按钮)。
//这将为我们提供选定的过滤器对象。
var filter=(发送者作为框架元素)。DataContext作为过滤器;
//将更改镜像到CollectionViewSource中。
//这很可能是不需要的。
if(filterViewSource.View!=null)
{
filtersViewSource.View.MoveCurrentTo(过滤器);
}
//确定选择了哪个过滤器
if(过滤器!=null)
{
//将结果镜像到相应的筛选器对象中,以允许
//未捕捉以反映更改时使用的单选按钮表示法
filter.Active=true;
//TODO:通过设置此选项响应活动筛选器中的更改。DefaultViewModel[“结果”]
//指向具有可绑定图像、标题、副标题和描述属性的项目集合
if(filter.Name.Equals(“全部”))
{
var tempResults=新列表();
//将每个组中的项目添加到临时结果中
//名单。
foreach(AllResultCollection中的var组)
{
tempResults.AddRange(组值);
}
//显示项目。
此.DefaultViewModel[“结果”]=tempResults;
}
else if(allresultCollection.ContainsKey(filter.Name))
{
此.DefaultViewModel[“结果”]=
新列表(AllResultCollection[filter.Name]);
}
//确保找到结果
客观结果;
i采集结果采集;
if(this.DefaultViewModel.TryGetValue(“结果”,out结果)&&
(resultsCollection=结果为ICollection)!=null&&
resultCollection.Count!=0)
{
VisualStateManager.GoToState(此“ResultsFound”为true);
返回;
}
}
//没有搜索结果时显示信息性文本。
VisualStateManager.GoToState(这是“NoResultsFound”,true);
}

提前感谢,非常感谢:-)

仍在努力解决这个问题,有熟悉searchpage的人吗?:)<代码>如果(numberOfMatchingItems>0){AllResultsCollection.Add(group.Customers,matchingItems);filterList.Add(new Filter(group.Customers,numberOfMatchingItems));}
此方法仍然失败,“最佳重载方法匹配”--具有一些无效参数