本文介绍了从ControlTemplate创建时,Window.DragMove()吞噬了所有MouseUp事件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,希望有人能提供帮助...

我正在创建一个"stickyNote"类应用程序;具有包含TextBox和其他相关控件的多个无边界窗口.我定义了一个"StickyWindow"自定义控件,其内容由generic.xaml中的ControlTemplate定义.在另一个窗口上,单击我实例化"一个新的StickyWindow和.Show().

基本上,用户可以在给定的SitckyWindow中单击两个控件,即Border和TextBox.我希望用户能够通过单击窗口中的任何位置来拖动窗口.当StickyWindow失去焦点时,我将TexBox.Focusable设置为false,从而使MouseDown能够通过,并为它连接了MouseLeftButtonDown和Up事件.在MouseButtonLeftDown上,我强制发送者,然后找到TemplatedParent(StickyWindow实例)并执行stickyWindow.DragMove().这样可以毫无问题地拖动窗口.但是,当用户释放拖动时,将不会触发MouseUp事件.如果我将DragMove()注释掉,那么每次都会得到MouseUp. ),则不会发生相同的问题.我以自己喜欢的方式收到所有MouseUp事件;所以在我看来,这与使用ControlTemplate创建窗口的内容有关.

有很多相关代码,或者我会发布它.如果您提出要求,我会提供.一个想法...


Hi all, hoping someone can help...

I am creating a "stickyNote" kinda app; with multiple, borderless windows containing a TextBox and other relevant controls. I have defined a "StickyWindow" custom control, whose Content is defined by a ControlTemplate in generic.xaml. From another window, on Click I instantiate a new StickyWindow and .Show().

There are basically two controls a user can click on in a given SitckyWindow, the Border and TextBox. I want the user to be able to DragMove the window by clicking anywhere in the window. When the StickyWindow looses focus, I set the TexBox.Focusable to false, enabling MouseDown to pass through, and have wired up MouseLeftButtonDown and Up events to it. On MouseButtonLeftDown I cast the sender then find the TemplatedParent (StickyWindow instance) and do a stickyWindow.DragMove(). This enables dragging of the window without problem; But NO MouseUp events will fire when the user releases the drag.

I have tried capturing the MouseUp from every UIElement in the tree, both applying it directly to the given controls events or by AddHandler to the StickyWindow instance. If I comment out DragMove(), I get the MouseUp every time.

One final twist to the problem.. If I programmatically create the new Window in C#, instantiating and adding all controls manually (Not via a ControlTemplate), the same issue does Not occur. I receive all MouseUp events any way I care to look; so this seems to me to be related to the use of ControlTemplate to create the window's contents.

There is a Lot of related code, or I would have posted it. If you ask, I will provide.
Any help is greatly appreciated!
- Forrest

解决方案


这篇关于从ControlTemplate创建时,Window.DragMove()吞噬了所有MouseUp事件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:36