0
我在將UI樹中生成的命令綁定到控件時遇到了問題。以下示例說明了我的觀點,在Grid
中的CommandBinding
不作用於Window中的InputBindings
。也許我不明白命令的重點,但我想有一個很好的解決方案,讓子控件根據窗口上的用戶輸入(窗口上的任何控件)進行操作。如何在兒童中綁定RoutedCommand?
<Window x:Class="SilverFit.Menu.Wpf.WpfWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.InputBindings>
<KeyBinding Command="Close" Key="Escape"/>
<MouseBinding Command="Close" MouseAction="RightClick" />
</Window.InputBindings>
<Grid Name="grid">
<Grid.CommandBindings>
<CommandBinding Command="Close" Executed="Close"/>
</Grid.CommandBindings>
</Grid>
</Window>
由於綁定在Window類上執行Close方法,因此命令目標是此示例中的Window。 – Wouter 2010-03-26 08:23:28
然後答案是,網格上的命令綁定只能看到針對網格內部事件的命令,或者由於路由事件模型,綁定子網中的路由命令沒有任何意義。 – 2010-04-09 20:43:05