我不想将我的点击处理程序放在APP.XAML.CS中,所以我想将它们留在pivot.XAML中。和pivot.XAML.CS
我该怎么做?
private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// MessageBox.Show("Pivot selection changed");
switch (((Pivot)sender).SelectedIndex)
{
case 0:
// MessageBox.Show("LoginAppBar launched");
ApplicationBar = ((ApplicationBar)Application.Current.Resources["zero"]);
break;
case 1:
// MessageBox.Show("DefaultAppBar launched");
ApplicationBar = ((ApplicationBar)Application.Current.Resources["one"]);
break;
case 2:
//Console.WriteLine("DefaultAppBar launched");
ApplicationBar = ((ApplicationBar)Application.Current.Resources["two"]);
break;
case 3:
//Console.WriteLine("DefaultAppBar launched");
ApplicationBar = ((ApplicationBar)Application.Current.Resources["three"]);
break;
}
}
答案 0 :(得分:0)
您可以通过附加相应数据透视表的应用栏来处理MSDN链接中所述的点击事件。您可以像这样添加或删除应用栏的按钮
ApplicationBarIconButton button1 = new ApplicationBarIconButton();
button1.IconUri = new Uri("/Images/icon_search.png", UriKind.Relative);
button1.Text = "Search";
ApplicationBar.Buttons.Add(button1); // adding button
button1.Click -= ShowSearch; // Adding event to button
button1.Click += ShowSearch;
//Removing second button
ApplicationBar.Buttons.Remove(ApplicationBar.Buttons[1] as ApplicationBarIconButton);
如果您遇到点击事件的问题,例如您在每个数据透视中都有搜索功能,并且您想要绑定搜索事件处理程序。为此,您可以绑定一个事件,在事件内部,您可以根据当前的Pivot选择
搜索值private void ShowSearch(object sender, EventArgs e)// event in the application bar button
{
if (NameOfPivot.SelectedIndex == 0)
{
// Do your action here
}
else if (NameOfPivot.SelectedIndex == 1)
{
// Do your action here
}
else if (NameOfPivot.SelectedIndex == 2)
{
// Do your action here
}
}