Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

UserControl event handling

Back to Forum: Tech Off
  • User profile image
    fawad.khan

    I have a usercontrol and a mainwindow for some reason only the mouse events are  being captured. nothing happens when I hook the keydown event.

     

    public partial class myControl : System.windows.usercontrol

    {

    this.KeyDown += delegate{MessageBox.show("key pressed");};

    this.PreviewKeyDown += delegate{MessageBox.show("key pressed");};

    // the following is captured

    this.MouseLeftButtonDown += delegate{MessageBox.show("clicked")'};

    }

     

    // the xaml for mainwindow

    <Window <insert namespaces>

    <grid name="grid1">

    <i:myControl  x:Name ="myControl1" />

    </grid>

    </window>

    Tunneling events are raised from the mainWindow and tunnel downwards to the souce. If I register a previewkeydown event, it should get raised in the mainwindow and then tunnel to the source i.e. the usercontrol.

     

     

  • User profile image
    fawad.khan

    Apparently the events get supressed if the control does not implement them even though it has the implementation i.e. grid does not raise KeyDown event but a textbox raises it.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.