Subscribe to the Button's events into a custom control
Posted
by ThitoO
on Stack Overflow
See other posts from Stack Overflow
or by ThitoO
Published on 2010-04-30T14:19:17Z
Indexed on
2010/04/30
14:27 UTC
Read the original article
Hit count: 325
Do you know how can I subscribe to an event of the base of my customControl ? I've a custom control with some dependency properties :
public class MyCustomControl : Button
{
static MyCustomControl ()
{
DefaultStyleKeyProperty.OverrideMetadata( typeof( MyCustomControl ), new FrameworkPropertyMetadata( typeof( MyCustomControl ) ) );
}
public ICommand KeyDownCommand
{
get { return (ICommand)GetValue( KeyDownCommandProperty ); }
set { SetValue( KeyDownCommandProperty, value ); }
}
public static readonly DependencyProperty KeyDownCommandProperty =
DependencyProperty.Register( "KeyDownCommand", typeof( ICommand ), typeof( MyCustomControl ) );
public ICommand KeyUpCommand
{
get { return (ICommand)GetValue( KeyUpCommandProperty ); }
set { SetValue( KeyUpCommandProperty, value ); }
}
public static readonly DependencyProperty KeyUpCommandProperty =
DependencyProperty.Register( "KeyUpCommand", typeof( ICommand ), typeof( MyCustomControl ) );
public ICommand KeyPressedCommand
{
get { return (ICommand)GetValue( KeyPressedCommandProperty ); }
set { SetValue( KeyPressedCommandProperty, value ); }
}
public static readonly DependencyProperty KeyPressedCommandProperty =
DependencyProperty.Register( "KeyPressedCommand", typeof( ICommand ), typeof( MyCustomControl ) );
}
And I whant to subscribe to Button's events (like MouseLeftButtonDown) to run some code in my customControl.
Do you know how can I do something like this in the constructor ?
static MyCustomControl()
{
DefaultStyleKeyProperty.OverrideMetadata( typeof( MyCustomControl ), new FrameworkPropertyMetadata( typeof( MyCustomControl ) ) );
MouseLeftButtonDownEvent += (object sender, MouseButtonEventArgs e) => "something";
}
Thanks for you help
© Stack Overflow or respective owner