C# 句柄按钮在基类中单击

C# 句柄按钮在基类中单击,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,有一个小问题我不明白。我有一个BasePage(类型为PhoneApplicationPage),我想在这里处理我所有的按钮 我的BasePage类没有什么特别之处,它只实现了一个按钮单击处理程序: 使用Microsoft.Phone.Controls; 使用System.Windows; 命名空间测试项目 { 公共部分类基页:PhoneApplicationPage { 受保护的无效按钮\u单击(对象发送器,路由目标e) { MessageBox.Show(“单击按钮”); } } } 实际

有一个小问题我不明白。我有一个
BasePage
(类型为
PhoneApplicationPage
),我想在这里处理我所有的按钮

我的BasePage类没有什么特别之处,它只实现了一个按钮单击处理程序:

使用Microsoft.Phone.Controls;
使用System.Windows;
命名空间测试项目
{
公共部分类基页:PhoneApplicationPage
{
受保护的无效按钮\u单击(对象发送器,路由目标e)
{
MessageBox.Show(“单击按钮”);
}
}
}
实际页面如下所示:

使用Microsoft.Phone.Controls;
使用Microsoft.Phone.Shell;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Navigation;
使用TestProject.Resources;
命名空间测试项目
{
公共部分类主页面:BasePage
{
公共主页()
{
初始化组件();
}
}
}
。。。在xaml中,我创建了一个按钮,该按钮应由BasePage类处理:


如果我尝试运行应用程序,我总是会遇到一个异常:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll
An exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll but was not handled in user code
An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll and wasn't handled before a managed/native boundary
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.Controls.Primitives.ButtonBase.Click'. [Line: 23 Position: 19]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at TestProject.MainPage.InitializeComponent()
   at TestProject.MainPage..ctor()
   --- End of inner exception stack trace ---
   at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)
   at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)
An exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll and wasn't handled before a managed/native boundary
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll
如果我将按钮的实现也添加到主页面,则一切正常:

新建受保护的无效按钮\u单击(对象发送器,路由目标)
{
基本。按钮点击(发送者,e);
}
有人能给我解释一下我如何处理BasePage类中的按钮点击(可能吗?)或者我做错了什么吗?


(提前多谢)

尝试更改
按钮的访问级别\u单击

试试这个

public partial class BasePage : PhoneApplicationPage
{
    public void Button_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("Button clicked");
    }
}


 new public void Button_Click(object sender, RoutedEventArgs e)
 {
    base.Button_Click(sender, e);
 }

将访问级别更改为public dose并不能解决问题,如果我不在主页上实现按钮单击,错误仍然存在-但是为什么我必须在
主页上实现
按钮单击
,我不能从基类(
BasePage
)派生它吗?