首页 \ 问答 \ wpf键盘焦点:菜单打开后失去焦点?(wpf keyboard focus: losing focus after menu opens?)

wpf键盘焦点:菜单打开后失去焦点?(wpf keyboard focus: losing focus after menu opens?)

这似乎很容易,但它绝对没有按预期工作。 在WPF 4.0中,我正在尝试使用菜单栏创建一个窗口,该菜单栏接受键盘快捷键...只是一个简单的窗口,顶部的菜单栏和其他一些东西(在AvalonDock内部,这可能是问题的一部分) )。

有一个问题:菜单栏和内容在另一个用户控件中(让我们称之为SadPanda ,因为它让我成为一个悲伤的熊猫),这是窗口的直接内容。 逻辑层次结构看起来像这样(不是实际的XAML):

<Window>
  <UserControl x:Name="SadPanda" Focusable="True" FocusManager.IsFocusScope="True">
    <Grid>
      <MenuBar/>
      <AvalonDock:DockingManager>
        <PandaFood>
      </AvalonDock:DockingManager>
    </Grid>
  </UserControl>
</Window>

窗口的内容需要访问窗口的Handle,所以它在窗口加载后设置如下:

window.Loaded += delegate { window.Content = new SadPanda(); };

菜单栏和快捷方式具有绑定到SadPanda的路由命令 ,当键盘焦点丢失时,输入手势不再起作用,因此悲伤的熊猫。 我补充说:

LostKeyboardFocus += (sender, e) => Debug.WriteLine("Lost focus to " + e.NewFocus);
GotKeyboardFocus += (sender, e) => Debug.WriteLine("Got focus from " + e.OldFocus);

......似乎重点是回到Window,而不是SadPanda本身。 如果我在窗口上设置Focusable =“False”,则焦点变为null; 甚至从未考虑过控制。 我尝试过(在评论中由alpha-mouse建议):

window.GotKeyboardFocus += delegate { Keyboard.Focus(sadPanda); };

即使这样也行不通 - 它可以防止菜单打开(它们会闪烁一秒钟,然后消失)或者文本框变得焦点......不知道为什么; 它似乎是完美的解决方案。

基本上,我希望用户控件具有顶级键盘焦点,而不是窗口。 实现这一目标的最简单方法是什么?


This seems really easy, but it's definitely not working as expected. In WPF 4.0, I'm trying to create a window with a menu bar that accepts keyboard shortcuts... Just a simple window, a menu bar at the top, and some other stuff (inside AvalonDock, which may be part of the issue).

There's one catch: the menu bar & content are in another user control (let's call it SadPanda, because it's making me a sad panda) that is the direct content of the window. The logical hierarchy looks something like this (not actual XAML):

<Window>
  <UserControl x:Name="SadPanda" Focusable="True" FocusManager.IsFocusScope="True">
    <Grid>
      <MenuBar/>
      <AvalonDock:DockingManager>
        <PandaFood>
      </AvalonDock:DockingManager>
    </Grid>
  </UserControl>
</Window>

The content of the window needs access to the window's Handle, so it's set after the window loads like this:

window.Loaded += delegate { window.Content = new SadPanda(); };

The menu bar & shortcuts have routed commands that are bound to SadPanda, and when the keyboard focus is lost, the input gestures no longer work, hence the sad panda. I added this:

LostKeyboardFocus += (sender, e) => Debug.WriteLine("Lost focus to " + e.NewFocus);
GotKeyboardFocus += (sender, e) => Debug.WriteLine("Got focus from " + e.OldFocus);

... and it seems that the focus is returning to the Window, rather than to SadPanda itself. If I set Focusable="False" on the window, then the focus goes to null; the control is never even considered. I tried (suggested by alpha-mouse in comments):

window.GotKeyboardFocus += delegate { Keyboard.Focus(sadPanda); };

Even this doesn't work -- it prevents menus from opening (they flash open for a second, then disappear) or text boxes from ever getting focus... Not sure why; it seems like the perfect solution.

Basically, I want the user control to have top-level keyboard focus, not the window. What's the easiest way to achieve this?


原文:https://stackoverflow.com/questions/4447929
更新时间:2023-03-25 17:03

最满意答案

您拥有的命令使用算术表达式1*xScale作为列号,对第二个表达式使用相同的结果。 你想要的是什么

plot 'datafile.data' u ($1*xScale):($2*yScale) pt 7 ps 1 lc rgb "red" title "[some title]"

The command you have uses the result of the arithmetic expression 1*xScale as column number, and same for the second expression. What you want is

plot 'datafile.data' u ($1*xScale):($2*yScale) pt 7 ps 1 lc rgb "red" title "[some title]"

相关问答

更多
  • 如果您可以访问grep等命令行工具,则可以在绘制数据文件之前对其进行过滤: set datafile sep ',' set xdata time set timefmt '%d/%m/%Y,%H:%M:%S' #DATA FILES plot '< grep -E ''^[0-9]{8,}'' PAS.csv' using 2:4 title 'Passive' with points pt 5 lc rgb 'red' 这将删除所有不以至少八位数字开头的行。 经测试可与4.6.3配合使用。 或者,如 ...
  • 为了在x轴上绘制日期/时间序列,您需要set xdata time 。 接下来,您需要告诉gnuplot日期/时间数据的格式。 在你的情况 set timefmt "%d-%b-%Y %H:%M" 应该做的伎俩。 这里显示了一些例子,以及%X -synonyms。 您可能想要设置x轴应显示的格式。 也许你的情况 set format x "%H:%M" 将是有道理的。 我无法用日期/时间周围的引号来绘制数据。 有了这个数据文件( Data.csv ): Series_1 12-Dec-2011 12:0 ...
  • 你需要告诉R你的xlim值是日期和时间。 所以尝试使用 xlim=c(as.POSIXct('2007-08-24 17:30:00', format="%Y-%m-%d %H:%M:%S"), as.POSIXct('2007-08-24 19:00:00', format="%Y-%m-%d %H:%M:%S")) 另外, as.numeric(U.)可能不会产生你真正想要的东西。 您应该使用as.numeric(as.character(U.))代替 ...
  • gnuplot> plot "./data.txt" using 2:1 with lp “使用”将允许您从数据中选择任意列。 gnuplot> plot "./data.txt" using 2:1 with lp "using" will allow you to select arbitrary columns from your data.
  • boxes样式期望x值是数字。 这很简单,我们可以给它一个伪列0,它基本上是脚本的行号: plot "categorie.dat" using (column(0)):2 ti col with boxes 现在您可能想要以某种方式在图表的第一列中的信息。 我假设你想让这些字符串成为x-tics: plot "categorie.dat" using (column(0)):2:xtic(1) ti col with boxes *小心这里,这可能不适用于您当前的boxwidth设置。 您可能需要考虑s ...
  • 我怀疑gnuplot每次绘制时都会读取整个文件,与读取相关行相反,然后是下一行,然后是下一行等。一种可能的策略是将粒子轨迹分成不同的文件,但特别是它可以通过简单的plot以及每个块的选择来帮助删除plot for ,而不是选择粒子的列,而是在同一块中为粒子位置设置相同的时间步。 现在您的数据看起来像这样: x1 y1 x2 y2 x3 y3 # Time step 1 x1 y1 x2 y2 x3 y3 # Time step 2 并且gnuplot需要为每个时间步和粒子读取一次文件。 如果您按如下方式构 ...
  • 您拥有的命令使用算术表达式1*xScale作为列号,对第二个表达式使用相同的结果。 你想要的是什么 plot 'datafile.data' u ($1*xScale):($2*yScale) pt 7 ps 1 lc rgb "red" title "[some title]" The command you have uses the result of the arithmetic expression 1*xScale as column number, and same for the seco ...
  • 这是一个分步教程的链接,如何制作你的情节。 第一部分 , 第二部分 (我猜你读过它) 我认为只有当你给出错误的“x”位置时,新的rect才会出现在左边。 这个return x(d.time - TS + T); 看起来很好。 所以我认为,在d.time和TS某个地方有问题。 您是否确定自己拥有相同TZ的时间戳? 2小时的差异会产生这样的效果。 或者可能是“新点”不是很近。 Here is a link to step-by-step tutorial how to make your plot. Part ...
  • u 3:2表示将第3列与第2列对比。 你没有这样的专栏,也没有情节 - 很容易。 只是滥用using 。 更新: 如何用不同颜色绘制每个文件,以及`system(...)`行的含义 绘图,修改最初找到的解决方案 a=system('a=`tempfile`; awk "{if ((FNR==1) && (NR!=1)) {printf \"\n\n\"}; print \$0}" *.txt > $a;echo $a;') plot a u 1:2:(column(-2)) with lines lc va ...
  • 使用自定义timefmt ,还必须使用以下格式指定xrange : set xrange ["Feb 04 00:00:00 GMT 2015":"Feb 09 00:00:00 GMT 2015"] 或者你可以整数,即时间戳来设置xrange。 对于5.0版,下面的行等同于上面的字符串设置: set xrange [1423008000:1423440000] 请注意,直到版本4.6 gnuplot使用2000年1月1日作为其时间戳的时间参考,并且仅从5.0开始标准Unix时间戳。 因此,直到4.6, ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。