c# .net grid app search page -
trying use guide https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868180.aspx
my app contains personal trainers, , personal trainers have customers. want able search customers.
this how far am: can search customers on first/lastname , how many results there are, ie results(3), not show them.
i've included data:
using personaltrainergridapp.data;
the if
statement in navigationhelper_loadstate
confusing me, i'm not sure have in it, , i'm not sure if filter_checked
correct.
anyone have pointers? formatting!
private async void navigationhelper_loadstate(object sender, loadstateeventargs e) { var querytext = e.navigationparameter string; // initialize results list. allresultscollection = new dictionary<string, ienumerable<sampledatasource>>(); // keep track of 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 entry "all" viewing search results. filterlist.insert(0, new filter("all", totalmatchingitems, true)); // communicate results through view model this.defaultviewmodel["querytext"] = '\"' + querytext + '\"'; this.defaultviewmodel["filters"] = filterlist; this.defaultviewmodel["showfilters"] = true; } /// <summary> /// invoked when filter selected using radiobutton when not snapped. /// </summary> /// <param name="sender">the selected radiobutton instance.</param> /// <param name="e">event data describing how radiobutton selected.</param> void filter_checked(object sender, routedeventargs e) { // retrieve data context of sender (the selected radio button). // gives selected filter object. var filter = (sender frameworkelement).datacontext filter; // mirror change collectionviewsource. // not needed. if (filtersviewsource.view != null) { filtersviewsource.view.movecurrentto(filter); } // determine filter selected if (filter != null) { // mirror results corresponding filter object allow // radiobutton representation used when not snapped reflect change filter.active = true; // todo: respond change in active filter setting this.defaultviewmodel["results"] // collection of items bindable image, title, subtitle, , description properties if (filter.name.equals("all")) { var tempresults = new list<sampledatasource>(); // add items each group temporary results // list. foreach (var group in allresultscollection) { tempresults.addrange(group.value); } // display items. this.defaultviewmodel["results"] = tempresults; } else if (allresultscollection.containskey(filter.name)) { this.defaultviewmodel["results"] = new list<sampledatasource>(allresultscollection[filter.name]); } // ensure results found object results; icollection resultscollection; if (this.defaultviewmodel.trygetvalue("results", out results) && (resultscollection = results icollection) != null && resultscollection.count != 0) { visualstatemanager.gotostate(this, "resultsfound", true); return; } } // display informational text when there no search results. visualstatemanager.gotostate(this, "noresultsfound", true); }
thanks in advance, appreciated :-)
Comments
Post a Comment