コード例 #1
0
        //Doesn't work for numbers.
        private async void ListViewArtists_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key.ToString() == "Back")
            {
                if (searchterm.Length > 0)
                {
                    searchterm           = searchterm.Remove(searchterm.Length - 1);
                    SearchTextBlock.Text = searchterm;
                }
                return;
            }
            if (e.Key.ToString().Length == 1)
            {
                SearchPopup.IsOpen = true;
                var listview = ListViewArtists;
                searchterm = searchterm + e.Key.ToString().ToUpperInvariant();
                Artist result = null;
                foreach (Artist artist in Artists)
                {
                    if (artist.name.Length >= searchterm.Length && artist.name.Substring(0, searchterm.Length).ToLowerInvariant() == searchterm.ToLowerInvariant())
                    {
                        result = artist;
                        break;
                    }
                }
                if (result == null)
                {
                    var r = SongListStorage.SearchArtists(searchterm);
                    if (r.Count > 0)
                    {
                        result = r[0];
                    }
                }
                if (result != null)
                {
                    listview.ScrollIntoView(result);
                    listview.SelectedItem = result;
                }
                var oldsearchterm = searchterm;
                SearchTextBlock.Text = searchterm;
                await Task.Delay(1000);

                if (searchterm.Equals(oldsearchterm))
                {
                    SearchPopup.IsOpen   = false;
                    searchterm           = "";
                    SearchTextBlock.Text = "";
                }
            }
        }
コード例 #2
0
        //Shows song suggestions in the searchbox based on what has been typed.
        private void SearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                var textresults = new List <StackPanel>();

                //Get Artists
                var artistsresults = SongListStorage.SearchArtists(SearchBox.Text);
                foreach (Artist artist in artistsresults)
                {
                    StackPanel stackpanel = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    stackpanel.Tag = artist;

                    SymbolIcon symbol = new SymbolIcon()
                    {
                        Symbol = Symbol.Contact,
                        Margin = new Thickness()
                        {
                            Right = 5
                        }
                    };
                    stackpanel.Children.Add(symbol);

                    TextBlock textblock = new TextBlock()
                    {
                        Text = artist.name,
                    };


                    stackpanel.Children.Add(textblock);

                    textresults.Add(stackpanel);
                }

                //Get Albums
                var albumresults = SongListStorage.SearchAlbums(SearchBox.Text, SongListStorage.Albums);
                foreach (Album album in albumresults)
                {
                    StackPanel stackpanel = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    stackpanel.Tag = album;

                    SymbolIcon symbol = new SymbolIcon()
                    {
                        Symbol = Symbol.Rotate,
                        Margin = new Thickness()
                        {
                            Right = 5
                        }
                    };
                    stackpanel.Children.Add(symbol);

                    TextBlock textblock = new TextBlock()
                    {
                        Text = album.Name,
                    };
                    stackpanel.Children.Add(textblock);

                    /*Button playbutton = new Button()
                     * {
                     *  Content = new SymbolIcon()
                     *  {
                     *      Symbol = Symbol.Play,
                     *      Margin = new Thickness() { Right = 5 },
                     *      Tag = album
                     *  },
                     * };
                     * playbutton.Click += Playbutton_Click;
                     * stackpanel.Children.Add(playbutton);*/


                    textresults.Add(stackpanel);
                }

                //Get Songs
                var songresults = SongListStorage.SearchSongs(SearchBox.Text);
                foreach (Song song in songresults)
                {
                    StackPanel stackpanel = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    stackpanel.Tag = song;

                    SymbolIcon symbol = new SymbolIcon()
                    {
                        Symbol = Symbol.Audio,
                        Margin = new Thickness()
                        {
                            Right = 5
                        }
                    };
                    stackpanel.Children.Add(symbol);

                    TextBlock textblock = new TextBlock()
                    {
                        Text = song.Title,
                    };
                    stackpanel.Children.Add(textblock);

                    /*Button playbutton = new Button()
                     * {
                     *  Content = new SymbolIcon()
                     *  {
                     *      Symbol = Symbol.Play,
                     *      Margin = new Thickness() { Right = 5 },
                     *      Tag = song
                     *  },
                     * };
                     * playbutton.Click += Playbutton_Click;
                     * stackpanel.Children.Add(playbutton);*/



                    textresults.Add(stackpanel);
                }

                SearchBox.ItemsSource = textresults;
            }
        }