I've done a WPF base usercontrol for all my usercontrols to inherit of. In this base usercontrol class, I want to have a button associated to a click event. I've made it like this :
public class MBaseUserControl : UserControl
{
//[...]
protected override void OnContentChanged(object oldContent, object newContent)
{
base.OnContentChanged(oldContent, newContent);
StackPanel mainPanel = new StackPanel();
EditButton = new Button();
EditButton.Height = EditButton.Width = 24;
EditButton.MouseEnter += EditButton_MouseEnter;
EditButton.MouseLeave += EditButton_MouseLeave;
EditButton.Click += new RoutedEventHandler(EditButton_Click);
EditButton.Background = Brushes.Transparent;
EditButton.BorderBrush = Brushes.Transparent;
EditButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
EditButton.VerticalAlignment = System.Windows.VerticalAlignment.Top;
StackPanel buttonPanel = new StackPanel();
Image editButtonImage = ImageTools.ConvertDrawingImageToWPFImage(Properties.Resources.edit, 24, 24);
buttonPanel.Children.Add(editButtonImage);
EditButton.Content = buttonPanel;
mainPanel.Children.Add(EditButton);
//Add this to new control
((IAddChild)newContent).AddChild(mainPanel);
SetCMSMode(false);
}
}
But when I click the button on GUI, nothing is firing (neither Mouse events or click event). What did I miss ?
Thanks by advance !