尝试使用https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868180.aspx
中的指南我的应用包含私人教练,私人教练包含他们的客户。 我希望能够搜索客户。
这就是我的目标:我可以在first / lastname上搜索客户,它会说出有多少结果,IE结果(3),但它不会显示它们。
我已经包含了我的数据:
using PersonalTrainerGridApp.Data;
if
中的navigationHelper_LoadState
声明令我感到困惑,我不确定其中包含哪些内容,而且我不确定Filter_Checked
是否正确
任何人都有一些指示?谢谢格式化!
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);
}
提前致谢,非常感谢: - )