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

  • Home
  • SEARCH
  • 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 874917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:11:00+00:00 2026-05-15T11:11:00+00:00

I’m using the InputManager to check if changes to controls are done by user

  • 0

I’m using the InputManager to check if changes to controls are done by user or code. This works fine, except when user uses the context menu for cut/copy/paste. If the user do ctrl+v in a textbox, InputManager correctly notices it. However, if the paste is done from the context menu of the textbox, the InputManager never fires the PreNotifyInput or PostNotifyInput events. Anyone knows why? Or how to detect that these user actions? Below is a working sample. The lower textblock never gets updated when user uses the cut/copy/paste menu in the above textbox since PreNotifyInput never fires.

XAML:

<Window x:Class="InputMgrDemo.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
    <StackPanel>
        <TextBox TextChanged="TextBox_TextChanged" />
        <TextBlock Name="_text" />
    </StackPanel>
</Window>

Code behind:

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace InputMgrDemo
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            InputManager.Current.PreNotifyInput += ((sender, e) => _userInput = true);
            InputManager.Current.PostNotifyInput += ((sender, args) => _userInput = false);
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (_userInput)
            {
                _text.Text = (sender as TextBox).Text;
            }
        }

        private bool _userInput;
    }
}
  • 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-15T11:11:01+00:00Added an answer on May 15, 2026 at 11:11 am

    Actually the PreNotifyInput event does fire on the MouseLeftButtonUp event, but then the PostNotifyInput fires before the actual paste occurs.

    Here is the sequence of operations:

    • The user releases the mouse button on the menu item
    • Your PreNotifyInput event handler is called
    • The MouseLeftButtonUp event is raised, which bubbles up to the MenuItem
    • The MenuItem handles the MouseButtonUp and converts it to OnClick
    • The OnClick raises a PreviewClickEvent, then schedules a dispatcher callback to raise the Click event and execute the command
    • Your PostNotifyInput event handler is called since the MouseLeftButtonUp event is handled

    • Any rendering scheduled by the Dispatcher completes

    • The Dispatcher invokes the callback in MenuItem

    • MenuItem fires the Click event, which does nothing
    • MenuItem executes the Paste command
    • TextBox handles the Paste command and pastes the data
    • TextBox fires the TextChanged event

    In WPF the effects of “user input” can be arbitrarily delayed by dispatcher callbacks, etc, so you cannot know whether a change is due to user input or not.

    In fact, theoretically speaking this is generally true. Consider the following scenarios:

    1. The user clicks a button elsewhere in your application which causes a new data to be loaded which updates your value.
    2. The user clicks a button in another application which writes a file, causing your application to refresh and display new data.
    3. The user walks to another computer and updates some data on a web site somewhere. Your application is monitoring this web site and detects the change.

    Clearly in each of these cases the change was caused by user input 😉 Do you see where I’m going with this? Philosophically there is no fundamental way to decide whether a change was made by your user or someone else.

    If what you really want is “any changes that occur between the time the user clicks the mouse or uses the keyboard in this application and the time the application goes idle,” you can implement this:

    InputManager.Current.PreNotifyInput += (sender, e) =>
    {
      _userInput = true;
      Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
      {
        _userInput = false;
      }));
    }; 
    

    But in this case if you have data coming in dynamically from an external feed it may be erroneously considered to be user input.

    Another approach is to flip yours upside down: Any time you refresh data from an external data source, set a flag saying you are doing so. Then any time you see changes with that flag not set, you assume it was user interaction. This may be easier to implement if you can ensure that all your external data updates happen above DispatcherPriority.Render.

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

Sidebar

Ask A Question

Stats

  • Questions 431k
  • Answers 431k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For the first release, augmented reality apps are out of… May 15, 2026 at 2:11 pm
  • Editorial Team
    Editorial Team added an answer AFAIK the <%$ Resources:Key %> syntax works only with resource… May 15, 2026 at 2:11 pm
  • Editorial Team
    Editorial Team added an answer Thanks for your comment. Basically I don't want to reject… May 15, 2026 at 2:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.