コード例 #1
0
        private void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            AutoCompleteBox autoComplete = e.UserState as AutoCompleteBox;

            if (autoComplete != null && e.Error == null && !e.Cancelled && !string.IsNullOrEmpty(e.Result))
            {
                List <string> data = new List <string>();
                try
                {
                    JsonArray result = (JsonArray)JsonArray.Parse(e.Result);
                    if (result.Count > 1)
                    {
                        string originalSearchString = result[0];
                        if (originalSearchString == autoComplete.SearchText)
                        {
                            JsonArray suggestions = (JsonArray)result[1];
                            foreach (JsonPrimitive suggestion in suggestions)
                            {
                                data.Add(suggestion);
                            }

                            // Diplay the AutoCompleteBox drop down with any suggestions
                            autoComplete.ItemsSource = data;
                            autoComplete.PopulateComplete();
                        }
                    }
                }
                catch
                {
                }
            }
        }
コード例 #2
0
        private async void OnPopulatingAsynchronous(object sender, PopulatingEventArgs e)
        {
            AutoCompleteBox source = (AutoCompleteBox)sender;

            // Cancel the populating value: this will allow us to call
            // PopulateComplete as necessary.
            e.Cancel = true;

            usergroups = await global.webSocketClient.Query <apiuser>("users", @"{ name: {$regex: '" + source.Text.Replace("\\", "\\\\") + "', $options: 'i'} }");


            //TestItems.Clear();
            if (usergroups == null)
            {
                return;
            }
            // Use the dispatcher to simulate an asynchronous callback when
            // data becomes available
            _ = Dispatcher.BeginInvoke(
                new System.Action(delegate()
            {
                //source.ItemsSource = new string[]
                //{
                //    e.Parameter + "1",
                //    e.Parameter + "2",
                //    e.Parameter + "3",
                //};
                //source.ItemsSource = TestItems.ToArray();
                source.ItemsSource = usergroups;

                // Population is complete
                source.PopulateComplete();
            }));
        }
コード例 #3
0
        private void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            AutoCompleteBox autoComplete = e.UserState as AutoCompleteBox;

            if (autoComplete != null && e.Error == null && !e.Cancelled && !string.IsNullOrEmpty(e.Result))
            {
                List <string> data = new List <string>();
                try
                {
#if SILVERLIGHT
                    JsonArray result = (JsonArray)JsonArray.Parse(e.Result);
                    if (result.Count > 1)
                    {
                        string originalSearchString = result[0];
                        if (originalSearchString == autoComplete.SearchText)
                        {
                            JsonArray suggestions = (JsonArray)result[1];
                            foreach (JsonPrimitive suggestion in suggestions)
                            {
                                data.Add(suggestion);
                            }
                        }
                    }
#else
                    System.Text.RegularExpressions.Regex jsonRegEx = new System.Text.RegularExpressions.Regex(
                        "^\\[(?<SearchItem>.*),\\[(?:(?<Items>[^,\\n]+),)*(?<LastItem>" +
                        ".*)?\\]\\]$", System.Text.RegularExpressions.RegexOptions.Multiline
                        | System.Text.RegularExpressions.RegexOptions.Compiled);
                    System.Text.RegularExpressions.Match match = jsonRegEx.Match(e.Result);
                    if (match.Groups["Items"] != null)
                    {
                        foreach (System.Text.RegularExpressions.Capture capture in match.Groups["Items"].Captures)
                        {
                            if (!String.IsNullOrEmpty(capture.Value))
                            {
                                data.Add(capture.Value.TrimStart('"').TrimEnd('"'));
                            }
                        }
                    }
                    if (match.Groups["LastItem"] != null && match.Groups["LastItem"].Captures.Count == 1 && !String.IsNullOrEmpty(match.Groups["LastItem"].Captures[0].Value))
                    {
                        data.Add(match.Groups["LastItem"].Captures[0].Value.TrimStart('"').TrimEnd('"'));
                    }
#endif

                    // Diplay the AutoCompleteBox drop down with any suggestions
                    if (data.Count > 0)
                    {
                        autoComplete.ItemsSource = data;
                        autoComplete.PopulateComplete();
                    }
                }
                catch
                {
                }
            }
        }
コード例 #4
0
        void UpdateQueryResults(AutoCompleteBox box, Task <object[]> task, CancellationToken token)
        {
            VerifyAccess();
            //
            // Last chance for cancellation... after this, we know we won't get canceled because cancellation can
            // only happen on this thread.
            //
            if (task.Status != TaskStatus.RanToCompletion || token.IsCancellationRequested)
            {
                return;
            }

            box.ItemsSource = task.Result;
            box.PopulateComplete();
        }
コード例 #5
0
        private void FilePathBox_OnPopulating(AutoCompleteBox box, string allowed_ext, object sender, PopulatingEventArgs e)
        {
            string text    = box.Text;
            string dirname = Path.GetDirectoryName(text);

            if (Directory.Exists(text) && !text.EndsWith("\\."))
            {
                dirname = text;
            }
            var candidates = new List <string>();

            if (!String.IsNullOrWhiteSpace(dirname))
            {
                try {
                    if (Directory.Exists(dirname) || Directory.Exists(Path.GetDirectoryName(dirname)))
                    {
                        string[] dirs = Directory.GetDirectories(dirname, "*.*", SearchOption.TopDirectoryOnly);


                        Array.ForEach(new[] { dirs }, (x) =>
                                      Array.ForEach(x, (y) => {
                            if (y.StartsWith(dirname, StringComparison.CurrentCultureIgnoreCase))
                            {
                                candidates.Add(y);
                            }
                        }));
                        if (!String.IsNullOrWhiteSpace(allowed_ext))
                        {
                            var files = Directory.GetFiles(dirname, "*." + allowed_ext, SearchOption.TopDirectoryOnly);
                            Array.ForEach(new[] { files }, (x) =>
                                          Array.ForEach(x, (y) => {
                                if (y.StartsWith(dirname, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    candidates.Add(y);
                                }
                            }));
                        }
                    }
                } catch (Exception) { }
            }
            box.ItemsSource = candidates;
            box.PopulateComplete();
        }
コード例 #6
0
        private void OnPopulatingAsynchronous(object sender, PopulatingEventArgs e)
        {
            AutoCompleteBox source = (AutoCompleteBox)sender;

            e.Cancel = true;
            _        = Dispatcher.BeginInvoke(
                new System.Action(delegate()
            {
                if (!string.IsNullOrEmpty(source.Text))
                {
                    source.ItemsSource = _items.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.ToLower().Contains(source.Text.ToLower())).ToArray();
                }
                else
                {
                    source.ItemsSource = _items;
                }
                source.PopulateComplete();
            }));
        }
コード例 #7
0
 private void OnPopulatingAsynchronous(object sender, PopulatingEventArgs e)
 {
     Log.FunctionIndent("InsertSelect", "OnPopulatingAsynchronous");
     try
     {
         AutoCompleteBox source = (AutoCompleteBox)sender;
         e.Cancel = true;
         _        = Dispatcher.BeginInvoke(
             new System.Action(delegate()
         {
             try
             {
                 if (!string.IsNullOrEmpty(source.Text))
                 {
                     source.ItemsSource = _items.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.ToLower().Contains(source.Text.ToLower())).ToArray();
                 }
                 else
                 {
                     source.ItemsSource = _items;
                 }
             }
             catch (Exception ex)
             {
                 ex.ToString();
             }
             try
             {
                 source.PopulateComplete();
             }
             catch (Exception)
             {
             }
         }));
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
     Log.FunctionOutdent("InsertSelect", "OnPopulatingAsynchronous");
 }
コード例 #8
0
        public void AutoCompleteBox_WhenPopulateComplete_ShouldUpdateTextCompletion()
        {
            //------------Setup for test--------------------------
            var autoCompleteBox = new AutoCompleteBox();

            autoCompleteBox.ItemsSource = new List <string> {
                "item1", "myValues", "anotherThing"
            };
            autoCompleteBox.FilterMode = AutoCompleteFilterMode.StartsWith;
            autoCompleteBox.IsTextCompletionEnabled = true;
            autoCompleteBox.TextBox    = new TextBox();
            autoCompleteBox.ItemFilter = (search, item) =>
            {
                if (search == "item1")
                {
                    return(true);
                }
                return(false);
            };
            autoCompleteBox.Text = "item1";
            autoCompleteBox.TextBox.SelectionStart = 5;
            var userCalledPopulateField = autoCompleteBox.GetType().GetField("_userCalledPopulate", System.Reflection.BindingFlags.NonPublic
                                                                             | System.Reflection.BindingFlags.Instance);

            userCalledPopulateField.SetValue(autoCompleteBox, true);
            var textSelectionStartField = autoCompleteBox.GetType().GetField("_textSelectionStart", System.Reflection.BindingFlags.NonPublic
                                                                             | System.Reflection.BindingFlags.Instance);

            textSelectionStartField.SetValue(autoCompleteBox, 0);
            //------------Execute Test---------------------------
            autoCompleteBox.PopulateComplete();
            //------------Assert Results-------------------------
            var filteredList = autoCompleteBox.View;

            Assert.IsNotNull(filteredList);
            Assert.AreEqual(3, filteredList.Count);
        }
コード例 #9
0
        /// <summary>
        /// The populating handler.
        /// </summary>
        /// <param name="sender">The source object.</param>
        /// <param name="e">The event data.</param>
        private void OnPopulatingAsynchronous(object sender, PopulatingEventArgs e)
        {
            AutoCompleteBox source = (AutoCompleteBox)sender;

            // Cancel the populating value: this will allow us to call
            // PopulateComplete as necessary.
            e.Cancel = true;

            // Use the dispatcher to simulate an asynchronous callback when
            // data becomes available
            Dispatcher.BeginInvoke(
                new Action(delegate()
            {
                source.ItemsSource = new string[]
                {
                    e.Parameter + "1",
                    e.Parameter + "2",
                    e.Parameter + "3",
                };

                // Population is complete
                source.PopulateComplete();
            }));
        }