如何Enable/Disable Application Bar

 

 简单点,下面的语句就管用:

((ApplicationBarIconButton)ApplicationBar.Buttons[0]).isEnabled = false;

((ApplicationBarIconButton)ApplicationBar.Buttons[1]).isEnabled = false;

 

((ApplicationBarIconButton)ApplicationBar.Buttons[0]).isEnabled = true;

((ApplicationBarIconButton)ApplicationBar.Buttons[1]).isEnabled = true;

 

想复杂点就这样:

 

namespace Microsoft.Phone.Shell
{
    public static class ApplicationBarHelpers
    {
        public static void Enable(this IApplicationBar appBar)
        {
            appBar.IsMenuEnabled = true;

            foreach (var obj in appBar.Buttons)
            {
                var button = obj as ApplicationBarIconButton;
                if (button != null)
                    button.IsEnabled = true;
            }
        }

        public static void Disable(this IApplicationBar appBar)
        {
            appBar.IsMenuEnabled = false;

            foreach (var obj in appBar.Buttons)
            {
                var button = obj as ApplicationBarIconButton;
                if (button != null)
                    button.IsEnabled = false;
            }
        }
    }
}

 

这样用的时候就简单了:

 

ApplicationBar.Enable();

ApplicationBar.Disable();

 

你可能感兴趣的:(application)