public MainPage()
{
InitializeComponent();
ApplicationBar = new ApplicationBar();
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = true;
ApplicationBar.BackgroundColor = System.Windows.Media.Colors.Transparent;
ApplicationBarIconButton add = new ApplicationBarIconButton();
add.IconUri = new Uri("Icons/appbar.add.rest.png", UriKind.Relative);
add.Text = "add a friend";
ApplicationBar.Buttons.Add(add);
add.Click += new EventHandler(add_Click); //ERROR
ApplicationBarIconButton list = new ApplicationBarIconButton();
list.IconUri = new Uri("icons/appbar.folder.rest.png",UriKind.Relative);
list.Text = "List";
ApplicationBar.Buttons.Add(list);
ApplicationBarIconButton about = new ApplicationBarIconButton();
about.IconUri = new Uri("icons/appbar.questionmark.rest.png",UriKind.Relative);
about.Text = "about";
ApplicationBar.Buttons.Add(about);
}
您是否在类的任何地方定义了一个名为add_Click的方法?它需要有以下签名:
void add_Click(object sender, EventArgs e)
{
// Put code to handle the click event in here
}
您需要将add_Click事件与实际的add_Click方法连接起来。我认为你缺少add_Click实现在你的代码。