Exemplo n.º 1
0
 private void ThePathNow_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (thePathNow.Text == "")
     {
         SuggestionPopup.IsOpen = false;
     }
     else if (SelectedNode != null && thePathNow.Text == SelectedNode.FullPath) //屏蔽刚扫描完和点击树节点时
     {
         SuggestionPopup.IsOpen = false;
     }
     else
     {
         List <SuggestItems> SuggestItemsList = new List <SuggestItems>();
         string FrontPath = "";
         string BackName  = "";
         for (int p = thePathNow.Text.Length - 1; p > 0; p--)
         {
             if (thePathNow.Text[p] == '\\')
             {
                 FrontPath = thePathNow.Text.Substring(0, p);
                 BackName  = thePathNow.Text.Substring(p + 1);
                 break;
             }
         }
         if (FrontPath != "")
         {
             DirectoryInfo dire = new DirectoryInfo(FrontPath);
             foreach (DirectoryInfo folder in dire.GetDirectories())
             {
                 int i;
                 for (i = 0; i < BackName.Length && i < folder.Name.Length; i++)
                 {
                     if (BackName[i] != folder.Name[i])
                     {
                         break;
                     }
                 }
                 if (i < BackName.Length)
                 {
                     continue;
                 }
                 SuggestItems item = new SuggestItems(folder.FullName);
                 SuggestItemsList.Add(item);
             }
             SuggestItemsListBox.ItemsSource = SuggestItemsList;
         }
         SuggestionPopup.IsOpen = (SuggestItemsList.Count > 0) ? true : false;
     }
 }
Exemplo n.º 2
0
        private async void UpdateProductSuggestions(string inputText)
        {
            if (string.IsNullOrEmpty(inputText) ||
                inputText.Length < 2)
            {
                return;
            }

            await DispatcherHelper.ExecuteOnUIThreadAsync(
                async() =>
            {
                SuggestItems.Clear();
                var suggestions = await _contosoRepository.Products.GetAsync(inputText);
                foreach (var product in suggestions)
                {
                    SuggestItems.Add(product);
                }
            });
        }