A textbox that supports a watermak hint. Based on: https://stackoverflow.com/a/15232752
Inheritance: TextBox
Exemplo n.º 1
0
        private WatermarkTextBox CreateReplyTextBox(ListBox panel)
        {
            var inputScope = new InputScope();

            inputScope.Names.Add(new InputScopeName()
            {
                NameValue = InputScopeNameValue.Chat
            });

            var textBox = new WatermarkTextBox();

            textBox.AcceptsReturn = true;
            textBox.TextWrapping  = TextWrapping.Wrap;
            textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            textBox.InputScope    = inputScope;
            textBox.WatermarkText = "댓글";
            textBox.Margin        = new Thickness(-10, 0, -10, 0);

            textBox.SizeChanged += (o1, e1) =>
            {
                if (FocusManager.GetFocusedElement() == textBox)
                {
                    VirtualizingStackPanel vstackPanel = (VirtualizingStackPanel)GetChildren(panel).FirstOrDefault(dobj => dobj is VirtualizingStackPanel);
                    if (vstackPanel != null)
                    {
                        vstackPanel.SetVerticalOffset(vstackPanel.ExtentHeight - vstackPanel.ViewportHeight);
                    }
                }
            };

            textBox.GotFocus  += (o1, e1) => UpdateAppBar();
            textBox.LostFocus += (o1, e1) => UpdateAppBar();

            return(textBox);
        }
Exemplo n.º 2
0
        public static FrameworkElement Render(TextInput input, RenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                var textBox = new WatermarkTextBox()
                {
                    Text = input.Value
                };
                if (input.IsMultiline == true)
                {
                    textBox.AcceptsReturn = true;
                    textBox.TextWrapping  = TextWrapping.Wrap;
                    textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
                }
                if (input.MaxLength > 0)
                {
                    textBox.MaxLength = input.MaxLength;
                }

                textBox.Watermark   = input.Placeholder;
                textBox.Style       = context.GetStyle($"Adaptive.Input.Text.{input.Style}");
                textBox.DataContext = input;
                context.InputBindings.Add(input.Id, () => textBox.Text);
                return(textBox);
            }
            else
            {
                var textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Occurs when content changes in the email address textbox.
        /// </summary>
        /// <param name="sender">The object that raised the event (TextBox).</param>
        /// <param name="e">The event data (RoutedEventArgs).</param>
        private void WatermarkTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            // Get the email address textbox
            _textBox = (WatermarkTextBox)sender;

            // If text has been entered
            if (!string.IsNullOrWhiteSpace(_textBox.Text))
            {
                // Get matching email addresses
                IEnumerable <EmailAddress> foundEmailAddresses = ComposeMailPage.Current.StoredEmailAddresses.Where(o => ((!string.IsNullOrEmpty(o.DisplayName) &&
                                                                                                                           o.DisplayName.ToLower().Contains(_textBox.Text.ToLower()))) ||
                                                                                                                    o.Address.ToLower().Contains(_textBox.Text.ToLower()));

                // If any matches are found
                if (foundEmailAddresses.Count() > 0)
                {
                    // Position the popup and display it
                    pSuggestions.VerticalOffset = icEmailAddress.ActualHeight + 1;
                    pSuggestions.IsOpen         = true;
                    lvEmailAddress.ItemsSource  = foundEmailAddresses;
                    lvEmailAddress.Visibility   = Visibility.Visible;
                    _textBox.Focus(FocusState.Programmatic);
                }
                // Else if there are not matches
                else
                {
                    // Close the popup
                    CloseSuggestions();
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Occurs when the email address textbox looses focus.
 /// </summary>
 /// <param name="sender">The object that raised the event (TextBox).</param>
 /// <param name="e">The event data (RoutedEventArgs).</param>
 private void WatermarkTextBox_LostFocus(object sender, RoutedEventArgs e)
 {
     // Get the email address textbox
     _textBox = (WatermarkTextBox)sender;
     // Check if email is valid
     IsValidEmail(null);
     // Close the popup
     CloseSuggestions();
 }
Exemplo n.º 5
0
 public static void HandleClick(this WatermarkTextBox txt)
 {
     txt.MouseRightButtonDown += (s, e) =>
     {
         if (Keyboard.IsKeyDown(Key.LeftShift))
         {
             Clipboard.SetText(txt.Text);
         }
     };
 }
Exemplo n.º 6
0
        // If value is null, then show and ellipsis. If its a number, show that. Otherwise blank.
        public override void SetContentAndTooltip(string value)
        {
            // CODECLEANUP this hack for counters, perhaps by updating to latest version of xceed.
            // This is a hack, but it works (sort of).
            // To explain, the IntegerUpDown control supplied with the WPFToolkit only allows numbers.
            // As we want it to also show both ellipsis and blanks, we have to coerce it to show those.
            // Ideally, we should modify the IntegerUpDown control to allow ellipsis and blanks instead of these hacks.
            // Its further complicated by the the way we have to set the bogus counter...

            // We access the textbox portion of the IntegerUpDown, so we can write directly into it if needed.
            WatermarkTextBox textBox = (WatermarkTextBox)this.ContentControl.Template.FindName("PART_TextBox", this.ContentControl);

            // When we get a null value, just show the ellipsis symbol in the textbox.
            if (value == null)
            {
                this.ContentControl.AllowSpin = false;
                if (textBox != null)
                {
                    textBox.Watermark = !string.IsNullOrEmpty(textBox.Text) ? Constant.Unicode.Ellipsis : String.Empty;
                    textBox.Text      = String.Empty;
                }
            }
            else
            {
                // We have a valid value, so reset the control and watermark
                this.ContentControl.AllowSpin = true;
                if (textBox != null)
                {
                    textBox.Watermark = String.Empty;
                }

                value = value.Trim();
                // The value is non-null, so its either a number or blank.
                // If its a number, just set it to that number
                if (int.TryParse(value, out int intvalue))
                {
                    if (textBox != null)
                    {
                        textBox.Text = intvalue.ToString();
                    }
                    this.ContentControl.Value = intvalue;
                }
                else
                {
                    // If its not a number, blank out the text
                    this.ContentControl.Text = String.Empty;
                    if (textBox != null)
                    {
                        textBox.Text = value;
                    }
                }
            }
            this.ContentControl.ToolTip = value ?? "Edit to change the " + this.Label + " for all selected images";
        }
Exemplo n.º 7
0
        /// <summary>
        /// Occurs when a keyboard key is pressed while the Email Address text box has focus.
        /// </summary>
        /// <param name="sender">The object that raised the event (TextBox).</param>
        /// <param name="e">The event data (KeyRoutedEventArgs).</param>
        private void tbEmailAddress_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            // Get the email address textbox
            _textBox = (WatermarkTextBox)sender;

            // Scroll to end as text is input
            _scrollViewer.UpdateLayout();
            _scrollViewer.ScrollToVerticalOffset(_scrollViewer.ActualHeight * 2);

            // If email is valid - handle event
            if (IsValidEmail(e.Key))
            {
                e.Handled = true;
            }
        }
Exemplo n.º 8
0
        // Behaviour: Revert the border whenever the control loses the keyboard focus
        private void ContentControl_LostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
        {
            this.ContentControl.BorderThickness = new Thickness(Constant.Control.BorderThicknessNormal);
            this.ContentControl.BorderBrush     = Constant.Control.BorderColorNormal;

            // This is a hack to ensure the ellipsis appears as needed.
            WatermarkTextBox textBox = (WatermarkTextBox)this.ContentControl.Template.FindName("PART_TextBox", this.ContentControl);

            if (textBox != null)
            {
                if ((string)textBox.Watermark == Constant.Unicode.Ellipsis)
                {
                    textBox.Text = String.Empty;
                }
            }
        }
Exemplo n.º 9
0
        public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                var textBox = new WatermarkTextBox()
                {
                    Text = input.Value
                };
                if (input.IsMultiline == true)
                {
                    textBox.AcceptsReturn = true;
                    textBox.TextWrapping  = TextWrapping.Wrap;
                    textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
                }
                if (input.MaxLength > 0)
                {
                    textBox.MaxLength = input.MaxLength;
                }

                textBox.Watermark   = input.Placeholder;
                textBox.Style       = context.GetStyle($"Adaptive.Input.Text.{input.Style}");
                textBox.DataContext = input;
                context.InputBindings.Add(input.Id, () => textBox.Text);
                if (input.InlineAction != null)
                {
                    if (context.Config.Actions.ShowCard.ActionMode == ShowCardActionMode.Inline &&
                        input.InlineAction.GetType() == typeof(AdaptiveShowCardAction))
                    {
                        context.Warnings.Add(new AdaptiveWarning(-1, "Inline ShowCard not supported for InlineAction"));
                    }
                    else
                    {
                        if (context.Config.SupportsInteractivity && context.ActionHandlers.IsSupported(input.InlineAction.GetType()))
                        {
                            return(AdaptiveTextInputRenderer.RenderInlineAction(input, context, textBox));
                        }
                    }
                }
                return(textBox);
            }
            else
            {
                var textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// If valid, add the user-provided Watermark and logo image details to local
        /// storage to be read by the background task
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private async void SetWatermarkButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsValidWatermark(Watermark))
            {
                // Save required values to local storage
                localStorage.SaveWatermarkTextToLocalStorage(Watermark);

                // If the check box for a logo image has been selected then add that too
                await AddLogoImageIfRequiredAsync();

                // Let the OnXpsDataAvailable finish by signalling that all the required parameters are now available
                SignalThatAllRequiredInformationIsAvailable();
            }
            else
            {
                // If bad number switch focus to the text box
                WatermarkTextBox.Focus(FocusState.Programmatic);
                // Highlight the text
                WatermarkTextBox.SelectAll();
            }
        }
Exemplo n.º 11
0
        private static Control ProvideDefaultControl(Binding binding, PropertyInfo propertyInfo,
                                                     bool isMultiLineTextBox = false)
        {
            var stringLengthAttribute = propertyInfo.GetAttribute <StringLengthAttribute>();
            var editableAttribute     = propertyInfo.GetAttribute <EditableAttribute>();


            var control = new WatermarkTextBox();

            control.SetBinding(TextBox.TextProperty, binding);

            if (stringLengthAttribute != null)
            {
                if (stringLengthAttribute.MaximumLength > 100)
                {
                    isMultiLineTextBox = true;
                }

                control.SetValue(TextBox.MaxLengthProperty, stringLengthAttribute.MaximumLength);
            }

            //set textbox to multiline textbox
            if (isMultiLineTextBox)
            {
                control.TextWrapping  = TextWrapping.Wrap;
                control.AcceptsReturn = true;
                control.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
                control.Height = 100;
            }


            control.SetBinding(WatermarkTextBox.WatermarkProperty, propertyInfo.GetDisplayPromptBinding());


            control.IsReadOnly = (editableAttribute != null && !editableAttribute.AllowEdit) ||
                                 binding.Mode == BindingMode.OneWay;

            return(control);
        }
Exemplo n.º 12
0
        public MenuTree()
        {
            InitializeComponent();

            _tbQSearch = new WatermarkTextBox("快速查找菜单项")
            {
                Margin                   = new Thickness(0),
                BorderThickness          = new Thickness(0),
                Background               = null,
                VerticalContentAlignment = VerticalAlignment.Center
            };

            _tbQSearch.TextChanged += new TextChangedEventHandler(tbQSearch_TextChanged);

            bdQuikSearch.Child        = _tbQSearch;
            popSearch.PlacementTarget = _tbQSearch;

            //new Pan().Invest(this, header);//可能RenderTransform会被其余代码覆盖(在MenuTree实例化后又指定了RenderTransform)
            var pan = new Pan();

            this.Loaded   += delegate { pan.Invest(this, header); };
            this.Unloaded += delegate { pan.UnInvest(header); };
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            originalForeground = Foreground;

            watermarkTextBox = (WatermarkTextBox)GetTemplateChild( "WatermarkElement" );

            passwordBox = (PasswordBox)GetTemplateChild( "ContentElement" );
            passwordBox.PasswordChanged += PasswordBoxPasswordChanged;
            passwordBox.TabIndex = PaswordBoxTabIndex;
            passwordBox.IsTabStop = PasswordBoxIsTabStop;

            if( !string.IsNullOrEmpty( passwordSetBeforeTemplateApplied ) )
            {
                passwordBox.Password = passwordSetBeforeTemplateApplied;
            }

            SetWatermarkVisibility();
        }
Exemplo n.º 14
0
 public TextBoxHandler()
 {
     Control = new WatermarkTextBox();
 }
        void DrawControls()
        {
            var type      = Models.ItemTypes.Types.FirstOrDefault(x => x.Type == TypeComboBox.SelectedItem.ToString());
            var infos     = type.GetPropertiesInfo();
            int propIndex = 1;

            foreach (var Property in infos)
            {
                Control valueControl = null;
                Label   nameTxt      = new Label();
                nameTxt.Content = Property.DisplayName;
                switch (Property.Type)
                {
                case "int":
                    valueControl      = new IntegerUpDown();
                    valueControl.Name = Property.Name;
                    ((IntegerUpDown)valueControl).Value = 0;
                    break;

                case "string":
                    valueControl = new WatermarkTextBox();
                    ((WatermarkTextBox)valueControl).Watermark = "...";
                    valueControl.Name = Property.Name;
                    break;

                case "bool":
                    valueControl      = new CheckBox();
                    valueControl.Name = Property.Name;
                    break;

                case "file":
                    valueControl      = new FileSelector();
                    valueControl.Name = Property.Name;
                    break;

                case "efxlist":
                    valueControl      = new EfxList();
                    valueControl.Name = Property.Name;
                    break;

                case "combo":
                    valueControl      = new ComboBox();
                    valueControl.Name = Property.Name;
                    foreach (var s in Property.Metadata)
                    {
                        ((ComboBox)valueControl).Items.Add(s);
                    }
                    ((ComboBox)valueControl).SelectedIndex = 0;
                    break;
                }

                theGrid.Children.Add(nameTxt);
                controls.Add(nameTxt);
                nameTxt.Margin = new Thickness(0, (propIndex * 26) + 5, 0, 0);
                if (valueControl != null)
                {
                    Grid.SetColumn(valueControl, 1);
                    valueControl.VerticalAlignment          = VerticalAlignment.Top;
                    valueControl.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                    valueControl.Margin = new Thickness(0, (propIndex * 26) + 5, 0, 0);
                    valueControl.Height = 26;
                    theGrid.Children.Add(valueControl);
                    controls.Add(valueControl);
                }

                propIndex++;
            }
            this.MinHeight = (propIndex + 1 * 26) * 10;
            this.Height    = (propIndex + 1 * 26) * 10;
        }
Exemplo n.º 16
0
        public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                var textBox = new WatermarkTextBox()
                {
                    Text = input.Value
                };
                if (input.IsMultiline == true)
                {
                    textBox.AcceptsReturn = true;
                    textBox.TextWrapping  = TextWrapping.Wrap;
                    textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
                }
                if (input.MaxLength > 0)
                {
                    textBox.MaxLength = input.MaxLength;
                }

                textBox.Watermark   = input.Placeholder;
                textBox.Style       = context.GetStyle($"Adaptive.Input.Text.{input.Style}");
                textBox.DataContext = input;
                context.InputBindings.Add(input.Id, () => textBox.Text);
                if (input.InlineAction != null)
                {
                    if (context.Config.Actions.ShowCard.ActionMode == ShowCardActionMode.Inline &&
                        input.InlineAction.GetType() == typeof(AdaptiveShowCardAction))
                    {
                        context.Warnings.Add(new AdaptiveWarning(-1, "Inline ShowCard not supported for InlineAction"));
                    }
                    else
                    {
                        if (context.Config.SupportsInteractivity && context.ActionHandlers.IsSupported(input.InlineAction.GetType()))
                        {
                            // Set up a parent view that holds textbox, separator and button
                            var parentView = new Grid();

                            // grid config for textbox
                            parentView.ColumnDefinitions.Add(new ColumnDefinition()
                            {
                                Width = new GridLength(1, GridUnitType.Star)
                            });
                            Grid.SetColumn(textBox, 0);
                            parentView.Children.Add(textBox);

                            // grid config for spacing
                            int spacing = context.Config.GetSpacing(AdaptiveSpacing.Default);
                            var uiSep   = new Grid
                            {
                                Style             = context.GetStyle($"Adaptive.Input.Text.InlineAction.Separator"),
                                VerticalAlignment = VerticalAlignment.Stretch,
                                Width             = spacing,
                            };
                            parentView.ColumnDefinitions.Add(new ColumnDefinition()
                            {
                                Width = new GridLength(spacing, GridUnitType.Pixel)
                            });
                            Grid.SetColumn(uiSep, 1);

                            // adding button
                            var   uiButton = new Button();
                            Style style    = context.GetStyle($"Adaptive.Input.Text.InlineAction.Button");
                            if (style != null)
                            {
                                uiButton.Style = style;
                            }

                            // this textblock becomes tooltip if icon url exists else becomes the tile for the button
                            var uiTitle = new TextBlock
                            {
                                Text = input.InlineAction.Title,
                            };

                            if (input.InlineAction.IconUrl != null)
                            {
                                var actionsConfig = context.Config.Actions;

                                var image = new AdaptiveImage(input.InlineAction.IconUrl)
                                {
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                    Type = "Adaptive.Input.Text.InlineAction.Image",
                                };

                                FrameworkElement uiIcon = null;
                                uiIcon           = AdaptiveImageRenderer.Render(image, context);
                                uiButton.Content = uiIcon;

                                // adjust height
                                textBox.Loaded += (sender, e) =>
                                {
                                    uiIcon.Height = textBox.ActualHeight;
                                };

                                uiButton.ToolTip = uiTitle;
                            }
                            else
                            {
                                uiTitle.FontSize = context.Config.GetFontSize(AdaptiveFontStyle.Default, AdaptiveTextSize.Default);
                                uiTitle.Style    = context.GetStyle($"Adaptive.Input.Text.InlineAction.Title");
                                uiButton.Content = uiTitle;
                            }

                            uiButton.Click += (sender, e) =>
                            {
                                context.InvokeAction(uiButton, new AdaptiveActionEventArgs(input.InlineAction));

                                // Prevent nested events from triggering
                                e.Handled = true;
                            };

                            parentView.ColumnDefinitions.Add(new ColumnDefinition()
                            {
                                Width = GridLength.Auto
                            });
                            Grid.SetColumn(uiButton, 2);
                            parentView.Children.Add(uiButton);
                            uiButton.VerticalAlignment = VerticalAlignment.Bottom;

                            textBox.KeyDown += (sender, e) =>
                            {
                                if (e.Key == System.Windows.Input.Key.Enter)
                                {
                                    context.InvokeAction(uiButton, new AdaptiveActionEventArgs(input.InlineAction));
                                    e.Handled = true;
                                }
                            };
                            return(parentView);
                        }
                    }
                }
                return(textBox);
            }
            else
            {
                var textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
Exemplo n.º 17
0
        private void ShowArticleText(ArticleData data)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke(() => ShowArticleText(data));
                return;
            }

            Contents.Children.Clear();

            // VirtualizingStackPanel을 쓰는 리스트 박스
            var panel = new ListBox();

            panel.ItemContainerStyle     = Resources["ListBoxItemStyle"] as Style;
            panel.ItemsPanel             = Resources["ListBoxItemsPanelTemplate"] as ItemsPanelTemplate;
            panel.ManipulationCompleted += (o, e) => this.Focus();

            // * 제목 title
            var title = new TextBlock();

            title.TextWrapping = TextWrapping.Wrap;
            title.Style        = Application.Current.Resources["DCViewTextMediumStyle"] as Style;
            title.Text         = HttpUtility.HtmlDecode(article.Title);
            title.FontWeight   = FontWeights.Bold;
            title.Margin       = new Thickness(0, 12, 0, 12);
            panel.Items.Add(title);

            // * 그림 불러오기 버튼
            List <Grid> imgContainers   = new List <Grid>();
            var         loadImageButton = CreateLoadImageButton(panel, imgContainers);

            panel.Items.Add(loadImageButton);

            // 그림 들어갈 자리에 Grid 하나씩 넣기..
            foreach (Picture pic in article.Pictures)
            {
                var grid = new Grid();
                grid.Tag    = pic;
                grid.Margin = new Thickness(0, 3, 0, 0);

                imgContainers.Add(grid);
                panel.Items.Add(grid);
            }

            // * 12픽셀을 띄기 위해서 마진이 12인 텍스트 블럭 삽입
            var margin = new TextBlock();

            margin.Margin = new Thickness(0, 0, 0, 12);
            panel.Items.Add(margin);

            // * 본문
            foreach (var elem in HtmlElementConverter.GetUIElementFromString(data.Text, tapAction))
            {
                panel.Items.Add(elem);

                if (elem is Grid && elem.Tag is Picture)
                {
                    imgContainers.Add((Grid)elem);
                }
            }

            // * 글쓴이 정보
            var status = new ArticleStatusView();

            status.DataContext         = new ArticleViewModel(article);
            status.HorizontalAlignment = HorizontalAlignment.Right;
            panel.Items.Add(status);

            // * 댓글
            foreach (var cmt in data.Comments)
            {
                var commentView = new CommentView();
                commentView.DataContext = new CommentViewModel(cmt);

                foreach (var grid in HtmlElementConverter.GetUIElementFromString(cmt.Text, tapAction))
                {
                    commentView.Contents.Children.Add(grid);

                    if (grid is Grid && grid.Tag is Picture)
                    {
                        imgContainers.Add((Grid)grid);
                    }
                }

                panel.Items.Add(commentView);
            }

            // * 댓글을 달 수 있으면 ReplyTextBox 넣기
            if (article.CanWriteComment)
            {
                // ReplyTextBox를 새로 만듦
                replyTextBox = CreateReplyTextBox(panel);
                panel.Items.Add(replyTextBox);
            }


            bool bPassiveLoading = (bool)IsolatedStorageSettings.ApplicationSettings["DCView.passive_loadimg"] && imgContainers.Count != 0;

            // * 수동읽기가 설정이 되어있으면 버튼을 활성화
            if (!bPassiveLoading)
            {
                loadImageButton.Visibility = Visibility.Collapsed;
                LoadImagesAsync(panel, imgContainers);
            }

            // Contents에 panel을 추가.
            Contents.Children.Add(panel);

            // *스크롤을 처음으로 되돌림
            panel.ScrollIntoView(title);
        }
Exemplo n.º 18
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            tb = GetTemplateChild("tbChild") as WatermarkTextBox;
            lb = GetTemplateChild("lbChild") as ListBox;
            g  = GetTemplateChild("spContainer") as Grid;

            if (tb == null || lb == null || g == null)
            {
                return;
            }


            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }

            var keys = Observable.FromEventPattern <KeyRoutedEventArgs>(tb, "KeyUp").Throttle(TimeSpan.FromSeconds(0.5), CoreDispatcherScheduler.Current);

            keys.Subscribe(evt =>
            {
                if (evt.EventArgs.Key == Windows.System.VirtualKey.Enter)
                {
                    HideAndSelectFirst();
                    return;
                }

                if (!isShowing)
                {
                    return;
                }

                lb.SelectionChanged -= lb_SelectionChanged;
                lb.Visibility        = Visibility.Collapsed;

                if (String.IsNullOrWhiteSpace(this.tb.Text) || this.ItemsSource == null || this.ItemsSource.Count == 0)
                {
                    return;
                }

                //var sel = (from d in this.ItemsSource where d.ToLower().RemoveDiacritics().StartsWith(this.tb.Text.ToLower().RemoveDiacritics()) select d);
                var sel = (from d in this.ItemsSource where SearchFunction(d, this.tb.Text) select d);

                if (sel.Any())
                {
                    lb.ItemsSource       = sel;
                    lb.Visibility        = Visibility.Visible;
                    lb.SelectionChanged += lb_SelectionChanged;
                }
            });

            tb.LostFocus += (s, e) => HideAndSelectFirst();
            tb.GotFocus  += (s, e) =>
            {
                isShowing = true;
            };

            if (ItemsSource != null)
            {
                lb.ItemsSource = ItemsSource;
            }

            g.MaxHeight = MaxHeight;
        }
Exemplo n.º 19
0
        private void ManageKeyUpOrDown(ref List<string> history, WatermarkTextBox current, bool isUp)
        {
            var index = history.IndexOf(current.Text);

            if (isUp) index++;
            else index--;

            if (index < 0 || index >= history.Count) return;

            current.Text = history[index];
        }
Exemplo n.º 20
0
 public static void GotFocused(WatermarkTextBox sender, RoutedEventArgs e)
 {
     sender.SelectAll();
 }
Exemplo n.º 21
0
 public static void GotFocused(WatermarkTextBox sender, RoutedEventArgs e)
 {
     sender.SelectAll();
 }
Exemplo n.º 22
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     filterBox = GetTemplateChild("filterBox") as WatermarkTextBox;
     if (filterBox != null) filterBox.TextChanged += filterBox_TextChanged;
 }