开发者

Howto bind a RoutedCommand in a child?

I am having trouble binding a Command that is generated up the UI tree to a control. The following example illustrates my point, the CommandBi开发者_开发知识库nding in Grid does not act on the InputBindings in Window. Maybe I do not understand the point of commands, but I would like to have a nice solution for child controls to act on user input on the Window (any control on the Window).

<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>


What object is acting as your command target? Whatever it is, it will need to be a child of the grid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜