【Windows Phone 8】ApplicationBarIconButton的添加及移除

【代码】

public partial class ProductDetailView : PhoneApplicationPage
    {
        private IList<IApplicationBarIconButton> appbarButtons;
        private ApplicationBarIconButton consultButton;
        private ApplicationBarIconButton favoriteButton;
        private ApplicationBarIconButton shareButton;
        private ApplicationBarIconButton catalogButton;
        private ApplicationBarIconButton cartButton;
     private bool isLoaded = false;
public ProductDetailView() { InitializeComponent(); } private void root_Loaded_1(object sender, RoutedEventArgs e) { if (!isLoaded) {
          // 初始化按钮 appbarButtons
= this.ApplicationBar.Buttons as IList<IApplicationBarIconButton>; favoriteButton = appbarButtons[0] as ApplicationBarIconButton; shareButton = appbarButtons[1] as ApplicationBarIconButton; catalogButton = appbarButtons[2] as ApplicationBarIconButton; cartButton = appbarButtons[3] as ApplicationBarIconButton; isLoaded = true; ChangeAppbar(); } } private void AddAppbarButton() { consultButton = new ApplicationBarIconButton(new Uri("/Resources/Images/ApplicationBar2/zixun1.png", UriKind.Relative)); consultButton.Text = "咨询"; consultButton.Click += consultButton_Click; }

    

 void consultButton_Click(object sender, EventArgs e)
 {

 }

     private void ChangeAppbarBtn()
        {
            if (isLoaded)
            {
                if (...)
                {
            // 只有一个咨询按钮 appbarButtons.Clear(); appbarButtons.Add(consultButton); }
else if (...) { appbarButtons.Clear();             // 恢复初始的4个按钮 appbarButtons.Add(favoriteButton); appbarButtons.Add(shareButton); appbarButtons.Add(catalogButton); appbarButtons.Add(cartButton); } } }
  }

 

posted @ 2013-12-31 15:56  Wiki-Locas  阅读(314)  评论(0编辑  收藏  举报