Howto bind a RoutedCommand in a child?

Posted by Wouter on Stack Overflow See other posts from Stack Overflow or by Wouter
Published on 2010-03-25T10:53:39Z Indexed on 2010/03/25 20:13 UTC
Read the original article Hit count: 673

Filed under:
|
|

I am having trouble binding a Command that is generated up the UI tree to a control. The following example illustrates my point, the CommandBinding 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>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about command