コード例 #1
0
        private async void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            switch (SearchButton.Visibility)
            {
            case Visibility.Collapsed:
                SearchBoxCollapse.Begin();
                return;

            default:
                break;
            }

            SearchBoxShow.Begin();
            SearchBox.Focus(FocusState.Programmatic);

            if (SearchBox.Text.IsNullorEmpty())
            {
                Context.SearchItems.Clear();

                // add clipboard text
                DataPackageView dataPackageView = Clipboard.GetContent();
                if (dataPackageView.Contains(StandardDataFormats.Text))
                {
                    string text = await dataPackageView.GetTextAsync();

                    if (!string.IsNullOrWhiteSpace(text))
                    {
                        Context.SearchItems.Add(new GenericMusicItemViewModel()
                        {
                            Title       = text,
                            InnerType   = MediaType.Placeholder,
                            Description = "\uE16D",
                        });
                    }
                }

                // add search history
                var searches = await SQLOperator.Current().GetSearchHistoryAsync();

                foreach (var item in searches)
                {
                    Context.SearchItems.Add(new GenericMusicItemViewModel()
                    {
                        Title       = item.Query,
                        InnerType   = MediaType.Placeholder,
                        Description = "\uE81C",
                    });
                }
            }
            if (!SearchBox.Items.IsNullorEmpty())
            {
                SearchBox.IsSuggestionListOpen = true;
            }
            else
            {
                SearchBox.IsSuggestionListOpen = false;
            }
        }
コード例 #2
0
 private void SearchBox_LosingFocus(UIElement sender, Windows.UI.Xaml.Input.LosingFocusEventArgs args)
 {
     if (args.NewFocusedElement is ListViewItem && !Context.SearchItems.IsNullorEmpty())
     {
         if (Context.SearchItems[0].InnerType == MediaType.Placeholder)
         {
             args.Cancel = true;
             return;
         }
     }
     SearchBoxCollapse.Begin();
 }