In my XAML I have a Button, with a button click event. I initialize the component in my MainWindow class : RibbonWindow. I have a the Button Click function in a separate class, but error window gives me “FooApplication.MainWindow” does not contain a definition for fooBtn_Click”, below is my code
namespace FooApplication1 {
public partial class MainWindow : RibbonWindow
{
public MainWindow()
{
InitializeComponent();
}
}
/* in another .cs class file located in the same project */
namespace FooApplication1
{
public partial class Jenny : MainWindow
{
public void btnApplyL_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello");
}
}
}
I tried to give Jenny a RibbonWindow partial, thinking it might be the issue, but gives error. What is wrong?
Your XAML file needs to point to the class responsible for the event handling via the
classattribute.Defining event handlers within the XAML forces the use of the
classattribute as it will dictate where the handlers exist. You can still have the partial classes; it’s just that the XAML needs to know which class is responsible for the event handling which modifying theclassattribute will address.In addition you will need to move the
InitializeComponent();call from theMainWindowclass to theJennyclass.