Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6163051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:45:37+00:00 2026-05-23T21:45:37+00:00

I was wondering if it’s possible to raise a PropertyChanged event when the user

  • 0

I was wondering if it’s possible to raise a PropertyChanged event when the user pauses while typing text into a TextBox? Or more specifically, I want to run a method X seconds after the user stops typing in a TextBox.

For example, I have a form with a TextBox and nothing else. The user types in a 1-9 digit Id value into the TextBox, a fairly resource-intensive background process loads the record.

I do not want to use the UpdateSouceTrigger=PropertyChanged because that would cause the resource-intensive background process to run whenever a character gets typed, so a 9-digit ID number starts off 9 of these processes.

I also don’t want to use UpdateSourceTrigger=LostFocus because there is nothing else on the form to make the TextBox lose focus.

So is there a way to cause my background process to run only after the user pauses when typing in the Id number?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:45:38+00:00Added an answer on May 23, 2026 at 9:45 pm

    Prepare for code-dump.

    I’ve done this with a WPF Fake Behavior (an attached DP that acts like a behavior). This code works, but it isn’t pretty and it may result in leaks. Probably need to replace all the references with weak references, etc.

    Here’s the Behavior class:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Threading;
    using System.Windows.Data;
    using System.ComponentModel;
    
    namespace BehaviorForDelayedTrigger
    {
        public static class DelayedUpdateBehavior
        {
            #region TargetProperty Attached DependencyProperty
            /// <summary>
            /// An Attached <see cref="DependencyProperty"/> of type <see cref="DependencyProperty"/> defined on <see cref="DependencyObject">DependencyObject instances</see>.
            /// </summary>
            public static readonly DependencyProperty TargetPropertyProperty = DependencyProperty.RegisterAttached(
              TargetPropertyPropertyName,
              typeof(DependencyProperty),
              typeof(DelayedUpdateBehavior),
              new FrameworkPropertyMetadata(null, OnTargetPropertyChanged)
            );
    
            /// <summary>
            /// The name of the <see cref="TargetPropertyProperty"/> Attached <see cref="DependencyProperty"/>.
            /// </summary>
            public const string TargetPropertyPropertyName = "TargetProperty";
    
            /// <summary>
            /// Sets the value of the <see cref="TargetPropertyProperty"/> on the given <paramref name="element"/>.
            /// </summary>
            /// <param name="element">The <see cref="DependencyObject">target element</see>.</param>
            public static void SetTargetProperty(DependencyObject element, DependencyProperty value)
            {
                element.SetValue(TargetPropertyProperty, value);
            }
    
            /// <summary>
            /// Gets the value of the <see cref="TargetPropertyProperty"/> as set on the given <paramref name="element"/>.
            /// </summary>
            /// <param name="element">The <see cref="DependencyObject">target element</see>.</param>
            /// <returns><see cref="DependencyProperty"/></returns>
            public static DependencyProperty GetTargetProperty(DependencyObject element)
            {
                return (DependencyProperty)element.GetValue(TargetPropertyProperty);
            }
    
            /// <summary>
            /// Called when <see cref="TargetPropertyProperty"/> changes
            /// </summary>
            /// <param name="d">The <see cref="DependencyObject">event source</see>.</param>
            /// <param name="e"><see cref="DependencyPropertyChangedEventArgs">event arguments</see></param>
            private static void OnTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                var prop = e.NewValue as DependencyProperty;
                if(prop == null)
                    return;
                d.Dispatcher.BeginInvoke(
                    (Action<DependencyObject, DependencyProperty>)
                        ((target, p) => new PropertyChangeTimer(target, p)), 
                    DispatcherPriority.ApplicationIdle, 
                    d, 
                    prop);
    
            }
            #endregion
            #region Milliseconds Attached DependencyProperty
            /// <summary>
            /// An Attached <see cref="DependencyProperty"/> of type <see cref="int"/> defined on <see cref="DependencyObject">DependencyObject instances</see>.
            /// </summary>
            public static readonly DependencyProperty MillisecondsProperty = DependencyProperty.RegisterAttached(
              MillisecondsPropertyName,
              typeof(int),
              typeof(DelayedUpdateBehavior),
              new FrameworkPropertyMetadata(1000)
            );
    
            /// <summary>
            /// The name of the <see cref="MillisecondsProperty"/> Attached <see cref="DependencyProperty"/>.
            /// </summary>
            public const string MillisecondsPropertyName = "Milliseconds";
    
            /// <summary>
            /// Sets the value of the <see cref="MillisecondsProperty"/> on the given <paramref name="element"/>.
            /// </summary>
            /// <param name="element">The <see cref="DependencyObject">target element</see>.</param>
            public static void SetMilliseconds(DependencyObject element, int value)
            {
                element.SetValue(MillisecondsProperty, value);
            }
    
            /// <summary>
            /// Gets the value of the <see cref="MillisecondsProperty"/> as set on the given <paramref name="element"/>.
            /// </summary>
            /// <param name="element">The <see cref="DependencyObject">target element</see>.</param>
            /// <returns><see cref="int"/></returns>
            public static int GetMilliseconds(DependencyObject element)
            {
                return (int)element.GetValue(MillisecondsProperty);
            }
            #endregion
            private class PropertyChangeTimer
            {
                private DispatcherTimer _timer;
                private BindingExpression _expression;
                public PropertyChangeTimer(DependencyObject target, DependencyProperty property)
                {
                    if (target == null)
                        throw new ArgumentNullException("target");
                    if (property == null)
                        throw new ArgumentNullException("property");
                    if (!BindingOperations.IsDataBound(target, property))
                        return;
                    _expression = BindingOperations.GetBindingExpression(target, property);
                    if (_expression == null)
                        throw new InvalidOperationException("No binding was found on property "+ property.Name + " on object " + target.GetType().FullName);
                    DependencyPropertyDescriptor.FromProperty(property, target.GetType()).AddValueChanged(target, OnPropertyChanged);
                }
    
                private void OnPropertyChanged(object sender, EventArgs e)
                {
                    if (_timer == null)
                    {
                        _timer = new DispatcherTimer();
                        int ms = DelayedUpdateBehavior.GetMilliseconds(sender as DependencyObject);
                        _timer.Interval = TimeSpan.FromMilliseconds(ms);
                        _timer.Tick += OnTimerTick;
                        _timer.Start();
                        return;
                    }
                    _timer.Stop();
                    _timer.Start();
                }
    
                private void OnTimerTick(object sender, EventArgs e)
                {
                    _expression.UpdateSource();
                    _expression.UpdateTarget();
                    _timer.Stop();
                    _timer = null;
                }
            }
        }
    }
    

    And here’s an example of how it is used:

    <Window
        x:Class="BehaviorForDelayedTrigger.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:t="clr-namespace:BehaviorForDelayedTrigger">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition
                    Height="auto" />
            </Grid.RowDefinitions>
            <Viewbox>
                <TextBlock
                    x:Name="TargetTextBlock"
                    Background="Red" />
            </Viewbox>
            <TextBox
                t:DelayedUpdateBehavior.TargetProperty="{x:Static TextBox.TextProperty}"
                t:DelayedUpdateBehavior.Milliseconds="1000"
                Grid.Row="1"
                Text="{Binding Text, ElementName=TargetTextBlock, UpdateSourceTrigger=Explicit}" />
        </Grid>
    </Window>
    

    The gist of this is…

    You set the attached property on the bound UIElement, passing in the DP you wish to delay. At this point, I have the target of the attached property and the property to be delayed, so I can set things up. I do have to wait until the binding is available, so I have to use the Dispatcher to instantiate my watcher class after databinding has been set up. Fail to do this and you can’t grab the binding expression.

    The watcher class grabs the binding and adds an update listener to the DependencyProperty. In the listener, I set up a timer (if we haven’t updated) or reset the timer. Once the Timer ticks, I fire off the binding expression.

    Again, it works, but it definitely needs cleanup. Also, you can just use the DP via its name with the following code snippet:

    FieldInfo fieldInfo = instance.GetType()
                                 .GetField(name, 
                                     BindingFlags.Public | 
                                     BindingFlags.Static | 
                                     BindingFlags.FlattenHierarchy);
    return (fieldInfo != null) ? (DependencyProperty)fieldInfo.GetValue(null) : null;
    

    You might have to tack “Property” onto name, but that’s easy compared to using x:Static.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if it is possible to incorporate regular expressions into a SQL statement on
Wondering if there is any Text to Speech software available as a plug in
Wondering if there's any not-too-hard way to edit non-form text in html 4. I
Wondering if this is possible. We have an 3rd Party library that contains identification
Wondering if it's possible to change a value returned from a queryset before sending
Wondering if this is possible or something with this effect. public class MyModel {
Wondering if there is any way to build and fire an event (e.g. on
Wondering if it is possible to have a version control of a MySQL database.
Wondering if it is possible for my claims aware application (ASP.NET) to save a
Wondering if it would ever be useful to index every possible state of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.