Expose an OnClick event in a custom template button , in silverlight
In Blend, I took a simple button --> Edit Template --> Create Empty... Added an image for the button, and fi开发者_如何学运维lled some visual states.
Now I want to expose an OnClick event :
public partial class MyButton : UserControl
{
public MyButton()
{
// Required to initialize variables
InitializeComponent();
button.Click += Click;
}
public event RoutedEventHandler Click;
}
But this doesn't work for me. What is wrong ?
It's not clear what exactly doesn't work here, but looks like you're trying to assign Click
delegate to your button.Click
event while Click
is empty. What you should do is assign another delegate which will invoke Click
.
Replace button.Click += Click;
with:
button.Click += (sender, args) => { if (Click != null) Click(sender, args); };
精彩评论