Ejemplo n.º 1
0
 public void SetProperty()
 {
     var box = new AutoCompleteBox();
     box.MinimumPrefixLength = -3;
     int length =  (int) box.MinimumPrefixLength;
     Assert.AreEqual(-1,length);
 }
 public void UpdatedTextUpdatesSelectedItem()
 {
     bool selectionChanged = false;
     string value = "String1";
     AutoCompleteBox acb = new AutoCompleteBox();
     acb.SelectionChanged += (e, o) => selectionChanged = true;
     acb.ItemsSource = new List<string> { value, "String2" };
     acb.Text = value;
     Assert.AreEqual(value, acb.SelectedItem, "The SelectedItem value does not equal the matched item value.");
     Assert.IsTrue(selectionChanged, "The SelectionChanged event was not fired.");
 }
Ejemplo n.º 3
0
        public void SetChildTemplate()
        {
            var box = new AutoCompleteBox();
            SilverUnit.SetTemplateChild(box, "Text", new TextBox());
            SilverUnit.SetTemplateChild(box, "Popup", new Popup());
            SilverUnit.SetTemplateChild(box, "SelectionAdapter", new ListBox());
            SilverUnit.SetTemplateChild(box, "DropDownToggle", new ToggleButton());

            box.OnApplyTemplate();
            SilverUnit.Assert.VisualStatedWasChangedTo("Normal",box,false);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Handles the SelectionChanged event of the txtForward control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
 private void txtForward_SelectionChanged(object sender, RoutedEventArgs e)
 {
     if (IsUsedForForward)
     {
         AutoCompleteBox currentPlace = sender as AutoCompleteBox;
         if (_dataContext.ForwardDns.Contains(currentPlace.Text))
         {
             btn_left.IsEnabled = true;
         }
         else
         {
             btn_left.IsEnabled = false;
         }
     }
 }
        private void DropDownToggle_Click(object sender, RoutedEventArgs e)
        {
            FrameworkElement fe  = sender as FrameworkElement;
            AutoCompleteBox  acb = null;

            while (fe != null && acb == null)
            {
                fe  = VisualTreeHelper.GetParent(fe) as FrameworkElement;
                acb = fe as AutoCompleteBox;
            }
            if (acb != null)
            {
                acb.IsDropDownOpen = !acb.IsDropDownOpen;
            }
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
 private void RunTest(Action <AutoCompleteBox, TextBox> test)
 {
     using (UnitTestApplication.Start(Services))
     {
         AutoCompleteBox control = CreateControl();
         control.Items = CreateSimpleStringArray();
         TextBox textBox = GetTextBox(control);
         var     window  = new Window {
             Content = control
         };
         window.ApplyTemplate();
         Dispatcher.UIThread.RunJobs();
         test.Invoke(control, textBox);
     }
 }
Ejemplo n.º 8
0
        private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            AutoCompleteBox acb = (AutoCompleteBox)sender;
            var             p   = (pitem)acb.SelectedItem;

            if (p != null)
            {
                SelectedItem = p.Item;
            }
            if (SelectedItem == null)
            {
                return;
            }
            search.Text        = SelectedItem.Name;
            okButton.IsEnabled = true;
        }
Ejemplo n.º 9
0
        public DirectoryView()
        {
            InitializeComponent();
            grid = this.FindControl <DataGrid>("DirectoryGrid");
            grid.PropertyChanged += SetOffset;
            control = this.FindControl <DockPanel>("MainPanel");
            control.PropertyChanged += SetGridHeight;
            manualFilter             = this.FindControl <AutoCompleteBox>("ManualFilter");
            var randomButton = this.FindControl <Button>("RandomButton");

            randomButton.Click += delegate
            {
                this.SelectRandom();
            };
            SearchControl = "SearchBox";
            InitializeTextBindings();
        }
Ejemplo n.º 10
0
 private void InputBox_KeyDown(object sender, KeyEventArgs e)
 {
     lastSelectionStart = InputBox.SelectionStart;
     if (e.Key == Key.Enter)
     {
         if (AutoCompleteBox.Items.Count != 0)
         {
             if (AutoCompleteBox.Focus())
             {
                 AutoCompleteBox.SelectedIndex = 0;
             }
         }
         else
         {
             CalcButton_Click(sender, e);
         }
     }
 }
Ejemplo n.º 11
0
        private void AssociatedObject_TextInput(object sender, TextCompositionEventArgs e)
        {
            if (string.IsNullOrEmpty(TriggerChar))
            {
                return;
            }

            var text = e.Text;

            if (text.StartsWith(TriggerChar, StringComparison.Ordinal))
            {
                AutoCompletePopup.IsOpen = true;
                AutoCompleteBox.Focus();
                HintAssist.SetHint(AutoCompleteBox, TriggerChar);
                AutoCompleteBox.Text = string.Empty;
                e.Handled            = true;
            }
        }
Ejemplo n.º 12
0
        public void AutoCompleteBox_SetMinimumPrefixLength_WhenTextLengthLessThan_ShouldNotFilter()
        {
            //------------Setup for test--------------------------
            var autoCompleteBox = new AutoCompleteBox();

            autoCompleteBox.ItemsSource = new List <string> {
                "item1", "myValues", "anotherThing"
            };
            autoCompleteBox.MinimumPrefixLength = 4;
            autoCompleteBox.FilterMode          = AutoCompleteFilterMode.Contains;
            //------------Execute Test---------------------------
            autoCompleteBox.Text = "ite";
            //------------Assert Results-------------------------
            var filteredList = autoCompleteBox.View;

            Assert.IsNotNull(filteredList);
            Assert.AreEqual(0, filteredList.Count);
        }
Ejemplo n.º 13
0
        private void AutoCompleteBox_KeyUp(object sender, KeyEventArgs e)
        {
            AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender;

            if (e.Key == Key.Enter)
            {
                if (autoCompleteBox.InputBindings != null && autoCompleteBox.InputBindings.Count > 0 &&
                    autoCompleteBox.InputBindings[0].GetType().Equals(typeof(KeyBinding)))
                {
                    KeyBinding keyBinding = autoCompleteBox.InputBindings[0] as KeyBinding;

                    if (keyBinding.Command != null)
                    {
                        keyBinding.Command.Execute(keyBinding.CommandParameter);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private static void OnFilterModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            OurAutoCompleteBox autoCompleteBox = d as OurAutoCompleteBox;
            AutoCompleteBox    base_box        = autoCompleteBox;
            var mode = (OurAutoCompleteFilterMode)e.NewValue;

            switch (mode)
            {
            case OurAutoCompleteFilterMode.ContainsSplit:
                base_box.FilterMode        = AutoCompleteFilterMode.Custom;
                autoCompleteBox.TextFilter = autoCompleteBox.MultiTextFilter;
                break;

            default:
                base_box.FilterMode = (AutoCompleteFilterMode)mode;
                break;
            }
        }
Ejemplo n.º 15
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();
            }));
        }
Ejemplo n.º 16
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();
        }
Ejemplo n.º 17
0
        private void DropDownToggle_Click(object sender, RoutedEventArgs e)
        {
            var             fe  = sender as FrameworkElement;
            AutoCompleteBox acb = null;

            while (fe != null && acb == null)
            {
                fe  = VisualTreeHelper.GetParent(fe) as FrameworkElement;
                acb = fe as AutoCompleteBox;
            }
            if (acb != null)
            {
                if (string.IsNullOrEmpty(acb.SearchText))
                {
                    acb.Text = string.Empty;
                }
                acb.IsDropDownOpen = !acb.IsDropDownOpen;
            }
        }
Ejemplo n.º 18
0
        public void AutoCompleteBox_WhenText_ShouldFilter()
        {
            //------------Setup for test--------------------------
            var autoCompleteBox = new AutoCompleteBox();

            autoCompleteBox.ItemsSource = new List <string> {
                "item1", "myValues", "anotherThing"
            };
            autoCompleteBox.FilterMode = AutoCompleteFilterMode.Contains;
            //------------Execute Test---------------------------
            autoCompleteBox.Text = "t";
            //------------Assert Results-------------------------
            var filteredList = autoCompleteBox.View;

            Assert.IsNotNull(filteredList);
            Assert.AreEqual(2, filteredList.Count);
            Assert.AreEqual("item1", filteredList[0]);
            Assert.AreEqual("anotherThing", filteredList[1]);
        }
        private void SetNnStoreFilter(
            IFilterViewModel <NomenclatureNumberModificationFilter, NomenclatureNumberModificationDto> filterViewModel,
            AutoCompleteBox autoCompleteBox,
            string enteredText)
        {
            filterViewModel.Filter.Code = string.Empty;
            filterViewModel.Filter.Name = string.Empty;

            if (Regex.IsMatch(enteredText, @"\d"))
            {
                autoCompleteBox.ValueMemberPath = HelperExtensions.GetName <NomenclatureNumberModificationDto>(x => x.Code);
                filterViewModel.Filter.Code     = enteredText;
            }
            else
            {
                autoCompleteBox.ValueMemberPath = HelperExtensions.GetName <NomenclatureNumberModificationDto>(x => x.Name);
                filterViewModel.Filter.Name     = enteredText;
            }
        }
Ejemplo n.º 20
0
        private void SetupTimerForAutoComplete(BindableDynamicDictionary model,
                                               string fieldName,
                                               AutoCompleteBox tb,
                                               Func <string, IEnumerable <string> > itemsGenerator)
        {
            string timerName = TimerName(fieldName);
            var    timer     = new System.Windows.Threading.DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(600)
            };

            timer.Tick += (sender, args) =>
            {
                timer.Stop(); // stop the timer, so that it can be started again the next time someone types
                PopulateAutoComplete(tb, itemsGenerator, model, fieldName);
            };

            model[timerName] = timer; // may need to save this...
        }
Ejemplo n.º 21
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;

            var result = new List <apiuser>();

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

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

            result.AddRange(_usergroups);
            usergroups = result.ToArray();


            //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();
            }));
        }
        public void TestAutoCompleteBoxBasicStyle()
        {
            AutoCompleteBox autoComplete = new AutoCompleteBox();

            SolidColorBrush background      = new SolidColorBrush(Colors.Green);
            SolidColorBrush borderBrush     = new SolidColorBrush(Colors.Orange);
            Thickness       borderThickness = new Thickness(1);
            Thickness       padding         = new Thickness(2);

            TestAsync(
                autoComplete,
                () => autoComplete.Background      = background,
                () => autoComplete.BorderBrush     = borderBrush,
                () => autoComplete.BorderThickness = borderThickness,
                () => autoComplete.Padding         = padding,
                () => Assert.AreEqual(Colors.Green, (autoComplete.Background as SolidColorBrush).Color),
                () => Assert.AreEqual(Colors.Orange, (autoComplete.BorderBrush as SolidColorBrush).Color),
                () => Assert.AreEqual(borderThickness, autoComplete.BorderThickness),
                () => Assert.AreEqual(padding, autoComplete.Padding));
        }
        public void TestAutoCompleteBoxBasicStyle()
        {
            AutoCompleteBox autoComplete = new AutoCompleteBox();

            SolidColorBrush background = new SolidColorBrush(Colors.Green);
            SolidColorBrush borderBrush = new SolidColorBrush(Colors.Orange);
            Thickness borderThickness = new Thickness(1);
            Thickness padding = new Thickness(2);

            TestAsync(
                autoComplete,
                () => autoComplete.Background = background,
                () => autoComplete.BorderBrush = borderBrush,
                () => autoComplete.BorderThickness = borderThickness,
                () => autoComplete.Padding = padding,
                () => Assert.AreEqual(Colors.Green, (autoComplete.Background as SolidColorBrush).Color),
                () => Assert.AreEqual(Colors.Orange, (autoComplete.BorderBrush as SolidColorBrush).Color),
                () => Assert.AreEqual(borderThickness, autoComplete.BorderThickness),
                () => Assert.AreEqual(padding, autoComplete.Padding));
        }
Ejemplo n.º 24
0
        private void PopulateAutoComplete(AutoCompleteBox tb,
                                          Func <string, IEnumerable <string> > itemsGenerator,
                                          BindableDynamicDictionary model,
                                          string itemFieldName)
        {
            var    source   = model[AutoSuggestSourceName(itemFieldName)] as ObservableCollection <string>;
            string busyName = BusyBindModelName(itemFieldName);

            model[busyName] = true;

            string textBoxTextCopy = tb.Text;

            Thread t = new Thread(() =>
            {
                try
                {
                    var items = itemsGenerator(textBoxTextCopy);

                    tb.Dispatcher.Invoke(() =>
                    {
                        source.Clear();
                        foreach (string i in items)
                        {
                            source.Add(i);
                        }
                    });
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    tb.Dispatcher.Invoke(() =>
                    {
                        model[busyName] = false;
                    });
                }
            });

            t.Start();
        }
Ejemplo n.º 25
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");
 }
Ejemplo n.º 26
0
        public List <AutoCompleteBox> GetPanelMembersDetailsByEmpName(bool isRequiredDept)
        {
            List <AutoCompleteBox> lstAutoCompBox = new List <AutoCompleteBox>();

            string lstValue = string.Empty;

            string[] valu;
            using (objSOMEntities = new SOMEntities())
            {
                lstValue = objSOMEntities.Configurations.Where(r => r.Module == "SOM" && r.Type == "EvaluationUserGrades" && r.IsActive == true)
                           .Select(r => r.Value).FirstOrDefault();
                valu = lstValue.Split(',');
            }

            using (objSOMEntities = new SOMEntities())
                using (objIPEntities = new IntranetPortalEntities())
                {
                    var emp = objIPEntities.EmpMasters.Where(r => r.IsActive == true && !string.IsNullOrEmpty(r.Grade)).ToList();

                    foreach (var item in emp)
                    {
                        if (valu.Contains(item.Grade))
                        {
                            AutoCompleteBox objAutoCompleteBox = new AutoCompleteBox();
                            if (isRequiredDept)
                            {
                                objAutoCompleteBox.ID = item.EmployeeNumber + "###" + item.Department;
                            }
                            else
                            {
                                objAutoCompleteBox.ID = item.EmployeeNumber;
                            }
                            objAutoCompleteBox.Value = item.EmployeeName;
                            lstAutoCompBox.Add(objAutoCompleteBox);
                        }
                    }
                }
            return(lstAutoCompBox);
        }
        public SizePanelViewModel(ViewModelBase parentVM) : base(parentVM.Controller)
        {
            //  SelectedMetricText = "";

            ClickOnAutoComplete = new DelegateCommand <object>(
                (sender) =>
            {
                try
                {
                    if (sender != null)
                    {
                        //Dimentions = new ObservableCollection<Metrics>(Data.Metrics.GetAll);
                        AutoCompleteBox buf = (AutoCompleteBox)sender;
                        if (!buf.IsDropDownOpen)
                        {
                            buf.IsDropDownOpen = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
                );
            _parentVM  = parentVM;
            Dimentions = new ObservableCollection <Metrics>(Data.Metrics.GetAll);
            //потому что я программист от бога
            if (parentVM.GetType() == typeof(SFSViewModel) || parentVM.GetType() == typeof(SPSViewModel))
            {
                DoubleSizeIsAvailable = true;
                TrueTestDoubleSize    = true;
                DoubleSizeAvailable   = false;
            }
            else
            {
                DoubleSizeIsAvailable = false;
                TrueTestDoubleSize    = false;
            }
        }
Ejemplo n.º 28
0
        private void AssociatedObject_TextInput(object sender, TextCompositionEventArgs e)
        {
            var text = e.Text;

            if (text.StartsWith(Constants.Twitter.HashTag, StringComparison.Ordinal))
            {
                FilterText = string.Empty;
                AutoCompletePopup.IsOpen      = true;
                AutoCompleteBox.ItemsSource   = FilteredHashtags;
                AutoCompleteBox.SelectedIndex = 0;
                Mode = SourceMode.Hashtags;
            }
            else if (text.StartsWith(Constants.Twitter.Mention, StringComparison.Ordinal))
            {
                FilterText = string.Empty;
                AutoCompletePopup.IsOpen      = true;
                AutoCompleteBox.ItemsSource   = FilteredUsers;
                AutoCompleteBox.SelectedIndex = 0;
                Mode = SourceMode.Users;
            }
            else if (AutoCompletePopup.IsOpen)
            {
                string selectedText = (string)AutoCompleteBox.SelectedItem;

                FilterText += text;

                var items = FilteredItems.ToList();

                Debug.WriteLine(string.Join(" - ", items));

                AutoCompleteBox.ItemsSource   = items;
                AutoCompleteBox.SelectedIndex = items.IndexOf(selectedText);
                if (AutoCompleteBox.SelectedIndex < 0)
                {
                    AutoCompleteBox.SelectedIndex = 0;
                }
                AutoCompleteBox.InvalidateProperty(ItemsControl.ItemsSourceProperty);
            }
        }
Ejemplo n.º 29
0
            public void IsFalseAfterASuggestionIsSelected()
            {
                var obs = Observable.Return(new BitmapImage());

                var suggestions = new List <AutoCompleteSuggestion>
                {
                    new AutoCompleteSuggestion("aaaa", obs, ":", ":"),
                    new AutoCompleteSuggestion("bbbb", obs, ":", ":"),
                    new AutoCompleteSuggestion("ccc", obs, ":", ":")
                };
                var result  = new AutoCompleteResult(2, new ReadOnlyCollection <AutoCompleteSuggestion>(suggestions));
                var advisor = Substitute.For <IAutoCompleteAdvisor>();

                advisor.GetAutoCompletionSuggestions(Arg.Any <string>(), Arg.Any <int>())
                .Returns(Observable.Return(result));

                var selectionAdapter = new TestSelectorSelectionAdapter();
                var textBox          = new TextBox();
                var autoCompleteBox  = new AutoCompleteBox(Substitute.For <IDpiManager>())
                {
                    SelectionAdapter = selectionAdapter,
                    Advisor          = advisor,
                    TextBox          = new TextBoxAutoCompleteTextInput {
                        TextBox = textBox
                    }
                };

                textBox.Text       = "A :a";
                textBox.CaretIndex = 4;
                Assert.AreEqual(4, textBox.CaretIndex);
                Assert.AreEqual(4, autoCompleteBox.TextBox.CaretIndex);
                Assert.True(autoCompleteBox.IsDropDownOpen);

                selectionAdapter.DoCommit();

                Assert.That(textBox.Text, Is.EqualTo("A :aaaa: "));
                Assert.False(autoCompleteBox.IsDropDownOpen);
            }
        public void UpdatedTextFiresTextChanged()
        {
            bool selectionChanged = false;
            bool textChanged = false;
            bool isLoaded = false;
            string value = "String1";
            AutoCompleteBox acb = new AutoCompleteBox();
            acb.TextChanged += (e, o) => textChanged = true;
            acb.SelectionChanged += (e, o) => selectionChanged = true;
            acb.Loaded += delegate { isLoaded = true; };
            EnqueueCallback(() => TestPanel.Children.Add(acb));
            EnqueueConditional(() => isLoaded);
            EnqueueCallback(
                () => acb.Text = "Hello world",
                () => acb.ItemsSource = new List<string> { value, "String2" },
                () => acb.Text = value,
                () => Assert.AreEqual(value, acb.SelectedItem, "The SelectedItem value does not equal the matched item value."),
                () => Assert.IsTrue(selectionChanged, "The SelectionChanged event was not fired."));

            // Effectively an assert: test will run forever if this is not fired
            EnqueueConditional(() => textChanged);
            EnqueueTestComplete();
        }
Ejemplo n.º 31
0
        public void AutoCompleteBox_WhenCustomSelection_ShouldNotUpdateText()
        {
            //------------Setup for test--------------------------
            var autoCompleteBox = new AutoCompleteBox();

            autoCompleteBox.ItemsSource = new List <string> {
                "item1", "myValues", "anotherThing"
            };
            autoCompleteBox.FilterMode      = AutoCompleteFilterMode.Contains;
            autoCompleteBox.Text            = "t";
            autoCompleteBox.CustomSelection = true;
            //------------Assert Preconditions-------------------
            var filteredList = autoCompleteBox.View;

            Assert.IsNotNull(filteredList);
            Assert.AreEqual(2, filteredList.Count);
            Assert.AreEqual("item1", filteredList[0]);
            Assert.AreEqual("anotherThing", filteredList[1]);
            //------------Execute Test---------------------------
            autoCompleteBox.SelectedItem = filteredList[1];
            //------------Assert Results-------------------------
            Assert.AreEqual("t", autoCompleteBox.Text);
        }
Ejemplo n.º 32
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);
        }
Ejemplo n.º 33
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();
            }));
        }
Ejemplo n.º 34
0
        private static void IsArrowVisible_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AutoCompleteBox autoCompleteBox = (AutoCompleteBox)d;

            if (autoCompleteBox._textBox != null && autoCompleteBox._dropDownToggle != null)
            {
                if ((bool)e.NewValue)
                {
                    //-----------------------------
                    // Show the toggle button
                    //-----------------------------
                    autoCompleteBox._textBox.Margin            = new Thickness(0, 0, 30, 0);
                    autoCompleteBox._dropDownToggle.Visibility = Visibility.Visible;
                }
                else
                {
                    //-----------------------------
                    // Hide the toggle button
                    //-----------------------------
                    autoCompleteBox._textBox.Margin            = new Thickness(0, 0, 0, 0);
                    autoCompleteBox._dropDownToggle.Visibility = Visibility.Collapsed;
                }
            }
        }
Ejemplo n.º 35
0
 private void AutoComplete_GotFocus(object sender, RoutedEventArgs e)
 {
     try
     {
         if (isSkillFocued == false)
         {
             AutoCompleteBox autoBox = sender as AutoCompleteBox;
             if (autoBox == null)
             {
                 return;
             }
             TextBox textBox = autoBox.Template.FindName("Text", autoBox) as TextBox;
             if (textBox != null)
             {
                 textBox.Focus();
             }
             isSkillFocued = true;
         }
     }
     catch (Exception generalException)
     {
         _logger.Error("Skills:AutoComplete_GotFocus():" + generalException.ToString());
     }
 }
 /// <summary>
 ///     Initializes a new instance of the AutoCompleteBoxAutomationPeer
 ///     class.
 /// </summary>
 /// <param name="owner">
 ///     The AutoCompleteBox that is associated with this
 ///     AutoCompleteBoxAutomationPeer.
 /// </param>
 public AutoCompleteBoxAutomationPeer(AutoCompleteBox owner)
     : base(owner)
 {
 }
 public void SetItemTemplate()
 {
     AutoCompleteBox ac = new AutoCompleteBox();
     ac.ItemTemplate = new DataTemplate();
     Assert.IsNotNull(ac.ItemTemplate, "The ItemTemplate was not set.");
 }
 public void StartingWithText()
 {
     AutoCompleteBox control = new AutoCompleteBox
     {
         Text = "Starting text."
     };
     control.ItemsSource = CreateSimpleStringArray();
 }
 public void SetItemContainerStyle()
 {
     AutoCompleteBox ac = new AutoCompleteBox();
     ac.ItemContainerStyle = new Style();
     Assert.IsNotNull(ac.ItemContainerStyle, "The ItemContainerStyle was not set.");
 }
 public void ChangeMaxDropDownHeightInvalid()
 {
     AutoCompleteBox ac = new AutoCompleteBox();
     ac.MaxDropDownHeight = -10;
 }
 public void InvalidFilterMode()
 {
     AutoCompleteBox control = new AutoCompleteBox();
     AutoCompleteFilterMode invalid = (AutoCompleteFilterMode)4321;
     control.SetValue(AutoCompleteBox.FilterModeProperty, invalid);
 }
 public void ChangeMaxDropDownHeight()
 {
     AutoCompleteBox ac = new AutoCompleteBox();
     ac.MaxDropDownHeight = 60;
     Assert.AreEqual(60, ac.MaxDropDownHeight);
 }
 public void ChangeMinimumPrefixLengthCoerce()
 {
     AutoCompleteBox ac = new AutoCompleteBox();
     ac.MinimumPrefixLength = 10;
     Assert.AreEqual(10, ac.MinimumPrefixLength);
     
     // This will throw the exception
     ac.MinimumPrefixLength = -99;
 }
 public void ChangeMinimumPrefixLength()
 {
     AutoCompleteBox ac = new AutoCompleteBox();
     ac.MinimumPrefixLength = 10;
     Assert.AreEqual(10, ac.MinimumPrefixLength);
     ac.MinimumPrefixLength = 1;
     Assert.AreEqual(1, ac.MinimumPrefixLength);
 }
        public void AdapterInXaml()
        {
            string xmlns = " xmlns=\"http://schemas.microsoft.com/client/2007\" " +
                " xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " +
                " xmlns:testing=\"clr-namespace:System.Windows.Controls.Testing;assembly=System.Windows.Controls.Testing\" " +
                " xmlns:input=\"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input\" ";
            string xmlChild = @"<Style " + xmlns + @" TargetType=""input:AutoCompleteBox"">
        <Setter Property=""Text"" Value=""Custom..."" />
        <Setter Property=""Template"">
            <Setter.Value>
                <ControlTemplate TargetType=""input:AutoCompleteBox"">
                    <Grid Margin=""{TemplateBinding Padding}"" Background=""{TemplateBinding Background}"">
                        <TextBox IsTabStop=""True"" x:Name=""Text"" Style=""{TemplateBinding TextBoxStyle}"" Margin=""0"" />
                        <Popup x:Name=""Popup"">
                            <Border x:Name=""PopupBorder"">
                                    <testing:XamlSelectionAdapter x:Name=""SelectionAdapter"" />
                            </Border>
                        </Popup>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>";
            Style customTemplate = XamlReader.Load(xmlChild) as Style;
            AutoCompleteBox control = new AutoCompleteBox
            {
                Style = customTemplate,
                ItemsSource = CreateSimpleStringArray()
            };

            bool isLoaded = false;
            OverriddenSelectionAdapter.Current = null;
            control.Loaded += delegate { isLoaded = true; };
            EnqueueCallback(() => TestPanel.Children.Add(control));
            EnqueueConditional(() => isLoaded);

            EnqueueTestComplete();
        }
 public void SetTextBoxStyle()
 {
     AutoCompleteBox ac = new AutoCompleteBox();
     ac.TextBoxStyle = new Style();
     Assert.IsNotNull(ac.TextBoxStyle, "The TextBoxStyle was not set.");
 }