예제 #1
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            TextView = e.NameScope.Find <TextView>("textView");

            LogicalChildren.Add(TextView);

            disposables.Add(TextDocumentProperty.Changed.Subscribe(args =>
            {
                if (args.NewValue != null)
                {
                    // Todo unsubscribe these events.
                    TextDocument.Changing += (sender, ee) =>
                    {
                        TextDocument?.UndoStack.PushOptional(new RestoreCaretAndSelectionUndoAction(this));

                        if (BeforeTextChangedCommand != null)
                        {
                            BeforeTextChangedCommand.Execute(null);
                        }
                    };

                    TextDocument.Changed += (sender, ee) =>
                    {
                        InvalidateVisual();

                        LineHeight = TextView.CharSize.Height;

                        if (TextChangedCommand != null && TextChangedCommand.CanExecute(null))
                        {
                            TextChangedCommand.Execute(null);
                        }
                    };
                }
            }));
        }
예제 #2
0
        private void TextChangedDelayTimer_Tick(object sender, EventArgs e)
        {
            textChangedDelayTimer.Stop();

            if (TextChangedCommand != null && TextChangedCommand.CanExecute(null))
            {
                TextChangedCommand.Execute(null);
            }
        }
예제 #3
0
        public async void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (HasFilterIcon)
            {
                var sbar = sender as Xamarin.Forms.SearchBar;
                if (string.IsNullOrWhiteSpace(sbar?.Text))
                {
                    iconFilter.TranslateTo(0, 0);
                }
                else
                {
                    int transX = -25; //Good for Android
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        transX = -80; //Good for iOS
                    }
                    if (iconFilter.TranslationX != transX)
                    {
                        iconFilter.TranslateTo(transX, 0, 100);
                    }
                }
            }

            if (TextChangedCommand != null)
            {
                if (cts != null)
                {
                    cts.Cancel();
                }
                cts = new CancellationTokenSource();
                var ctoken = cts.Token;

                try
                {
                    var millisDelay = TextChangedDelay > 0 ? TextChangedDelay : 650;
                    await Task.Delay(millisDelay, ctoken);

                    if (ctoken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (TextChangedCommand.CanExecute(null))
                    {
                        TextChangedCommand?.Execute(null);
                    }
                }
                catch (OperationCanceledException)
                {
                    // Expected
                }
            }
        }
예제 #4
0
        void OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (TextChangedCommand == null)
            {
                return;
            }

            var param = AssociatedObject.Text;

            if (TextChangedCommand.CanExecute(param))
            {
                TextChangedCommand.Execute(param);
            }
        }
예제 #5
0
        private void ExtendedSearchBar_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                var param = TextChangedCommandParameter ?? e.NewTextValue;

                if (TextChangedCommand != null && TextChangedCommand.CanExecute(param))
                {
                    TextChangedCommand.Execute(param);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
예제 #6
0
        public SearchBar()
        {
            TextChanged += (e, a) =>
            {
                if (TextChangedCommand != null && TextChangedCommand.CanExecute(null))
                {
                    TextChangedCommand.Execute(null);
                }
            };

            TextChanged += (e, a) =>
            {
                if (AutoSearch)
                {
                    if (SearchCommand != null && SearchCommand.CanExecute(null))
                    {
                        SearchCommand.Execute(null);
                    }
                }
            };
        }