C# 按钮位于tabitem下(tabcontrol内),但处理程序需要位于主窗口中

C# 按钮位于tabitem下(tabcontrol内),但处理程序需要位于主窗口中,c#,wpf,tabcontrol,C#,Wpf,Tabcontrol,我有一个主窗口,其中包含一些控件,包括tabcontrol。选项卡控件本身有多个选项卡项。每个选项卡项都有独特的设计。当用户单击某个选项卡项中的按钮时,我希望事件处理程序位于主窗口的.cs文件中。我想不出一个办法,有谁能启发我吗?我的语法可能不完美,但是这个呢: public interface ITabControlWithNotifications { void OnButtonClicked(...); } public sealed class TabControlWithNo

我有一个主窗口,其中包含一些控件,包括tabcontrol。选项卡控件本身有多个选项卡项。每个选项卡项都有独特的设计。当用户单击某个选项卡项中的按钮时,我希望事件处理程序位于主窗口的.cs文件中。我想不出一个办法,有谁能启发我吗?

我的语法可能不完美,但是这个呢:

public interface ITabControlWithNotifications
{
    void OnButtonClicked(...);
}

public sealed class TabControlWithNotifications : TabControl, ITabControlWithNotifications
{
    public void OnButtonClicked(...)
    {
        ...
    }
}

public sealed class TabPageWithNotifications : TabPage
{
    private readonly ITabControlWithNotifications parentTabControl;

    public TabPageWithNotifications(ITabControlWithNotifications tabControlWithNotifications)
    {
        this.parentTabControl = tabControlWithNotifications;
        this.InitialzeComponents();
    }

    ... ClickEventHandler(...)
    {
        this.parentTabControl.OnButtonClicked(...);
    }
}

public sealed class TabControlFactory
{
    public void Build()
    {
        var parentTabControl = new TabControlWithNotifications();
        var tabPage1 = new TabPageWithNotifications(parentTabControl);
        var tabPage2 = new TabPageWithNotifications(parentTabControl);
        var tabPage3 = new TabPageWithNotifications(parentTabControl);
        parentTabControl.Controls.Add(tabPage1);
        parentTabControl.Controls.Add(tabPage2);
        parentTabControl.Controls.Add(tabPage3);
    }
}