ApplicationBarIconButton is null

前端 未结 5 762
一个人的身影
一个人的身影 2021-02-07 02:32

Why is my ApplicationBarIconButton null?


    

        
相关标签:
5条回答
  • 2021-02-07 03:15

    I made this mistake today, the x:Name is ignored.

    The ApplicationBar is part of the page already, whether you create it in XAML or not. There is no need to create a new one. Just use the ApplicationBar property in the code behind file.

    Initialize Component();
    ApplicationBar.IsEnabled = true;
    
    0 讨论(0)
  • 2021-02-07 03:21

    I use a bindable app bar control from here The download link is at the bottom of the article.

    Makes life much easier and saves you from having to put code in the code behind.

    0 讨论(0)
  • 2021-02-07 03:22

    I remember running into this issue before: there's an explanation here. An easy workaround is just to instantiate it in code-behind rather than xaml (like here).

    private ApplicationBarIconButton SaveEdit;
    private void InitAppBar()
    {
         ApplicationBar appBar = new ApplicationBar();
    
         SaveEdit = new ApplicationBarIconButton(new Uri("images/appbar.check.rest.png", UriKind.Relative));
         SaveEdit.Click += new EventHandler(OnClick_Check);
         SaveEdit.Text = Strings.Save_button;
         appBar.Buttons.Add(SaveEdit);
    
         ApplicationBarIconButton CancelEdit = new ApplicationBarIconButton(new Uri("images/appbar.close.rest.png", UriKind.Relative));
         CancelEdit.Click += new EventHandler(OnClick_Cancel);
         CancelEdit.Text = Strings.Cancel_button;
         appBar.Buttons.Add(CancelEdit);
    
         ApplicationBar = appBar;
    }
    
    0 讨论(0)
  • 2021-02-07 03:35

    try this

    Microsoft.Phone.Shell.ApplicationBarIconButton btn = ApplicationBar.Buttons[0] as Microsoft.Phone.Shell.ApplicationBarIconButton;
    btn.IsEnabled = false;
    
    0 讨论(0)
  • 2021-02-07 03:36

    I do it so, example for change icon

    ApplicationBarIconButton btn =  (ApplicationBarIconButton)ApplicationBar.Buttons[0];
    btn.IconUri = new Uri("/images/play.png", UriKind.Relative);
    
    0 讨论(0)
提交回复
热议问题