English 中文(简体)
投稿人忽视了从菜单开始的切割/范围/产物
原标题:InputManager ignores cut/copy/paste when initiated from menu

Im利用InputManager来检查控制的变化是否由用户或代码进行。 除用户使用切割/拷贝/帕斯图时外,该工程课以罚款。 如果用户在文本箱中做剪辑+v,InputManager正确地通知。 然而,如果从文本框的正文中划出历史,那么投稿人就永远不会向专利局或公证局发动火灾。 任何人都知道为什么? 或者如何发现这些用户的行动? 以下是一份工作样本。 在用户使用上述文本框中的切割/拷贝/帕斯特菜单时,从没有发生火灾以来,较低文本栏目从未更新过。

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>

背后法典:

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;
    }
}
最佳回答

事实上,“预先确认”活动对MouseLeftButtonUp活动造成火灾,但随后,在实际发生之前,“事后起义”火灾。

这里是行动顺序:

  • 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
  • www.un.org/Depts/DGACM/index_spanish.htm 阁下 投稿人称为 自MouseLeftButton以来 事件处理

  • 发货人安排的任何送货单

  • 发货人援引MenduItem的退席。

  • 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

在森林问题合作伙伴关系中,“用户投入”的影响可能被发送者呼吁等任意推迟,因此,你无法知道,变化是否是由于用户的投入。

事实上,从理论上讲,情况一般都是如此。 考虑以下假设情景:

  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.

很明显,在这些情况下,变化是由用户投入造成的。 你们看看一看我是怎么办? 从理论上讲,根本无法决定用户或其他人是否做了改动。

如果你真的希望是“用户点燃 mo或使用该应用程序的关键板到提出申请时发生的任何变化”,你可以实施:

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

但在这种情况下,如果你有动态地从外部输入的数据,则可能错误地认为是用户的投入。

另一种做法是 your倒你: 每次你更新外部数据来源的数据时,都会树立旗帜,表明你正在这样做。 在你看到该国旗未设定的变化时,你假定该国旗是用户互动。 如果你能够确保你的所有外部数据更新都发生在离散状态之上,这可能会更容易执行。 投标。

问题回答

暂无回答




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签