Monday, 30 September 2013

disable appbar button programatically?

disable appbar button programatically?

I have two icons (buttons) in my appbar. One is next and another one is
back. While user viewing the first, there is no use of back button and
also for last page, no use of next button. So, I wanna decide to disable
appbar icons programmatically. Below is my code. But, App breaks for my
code.
Breaking reason:
An exception of type 'System.InvalidOperationException' occurred in
Microsoft.Phone.ni.dll but was not handled in user code
If there is a handler for this exception, the program may be safely
continued.
XAML CODE:
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar Mode="Default" Opacity="1.0"
IsMenuEnabled="False" IsVisible="True">
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
C# CODE:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("Page"))
{
var page = NavigationContext.QueryString["Page"];
IsolatedStorageSettings.ApplicationSettings["File"] = page;
IsolatedStorageSettings.ApplicationSettings.Save();
browser.Navigate(new Uri("htmlfiles/" + page + ".html",
UriKind.Relative));
if (page == "1")
{
ApplicationBarIconButton b = new ApplicationBarIconButton();
b.Text = "next";
b.IconUri = new Uri("Assets/next.png", UriKind.Relative);
ApplicationBar.Buttons.Add(b);
}
if (page == "69")
{
ApplicationBarIconButton b = new ApplicationBarIconButton();
b.Text = "back";
b.IconUri = new Uri("Assets/back.png", UriKind.Relative);
ApplicationBar.Buttons.Add(b);
}
else
{
ApplicationBarIconButton a = new ApplicationBarIconButton();
a.Text = "next";
a.IconUri = new Uri("Assets/next.png", UriKind.Relative);
ApplicationBar.Buttons.Add(a);
ApplicationBarIconButton b = new ApplicationBarIconButton();
b.Text = "back";
b.IconUri = new Uri("Assets/back.png", UriKind.Relative);
ApplicationBar.Buttons.Add(b);
}
}
}

No comments:

Post a Comment