I’m developing a Windows Phone 7.1 application.
I have the following folders structure:
- Images (**folder**)
|
- appbar.questionmark.rest.png
- Views(**folder**)
|
- About.xaml
- MainPage.xaml
…
I’m trying to create an app bar programmatically with:
private void SetUpAppBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton helpButton = new ApplicationBarIconButton(new Uri("..//Images//appbar.questionmark.rest.png", UriKind.Relative));
helpButton.Text = AppResources.Help;
helpButton.Click += new EventHandler(helpButton_Click);
ApplicationBar.Buttons.Add(helpButton);
// Create a new menu item with the localized string from AppResources.
ApplicationBarMenuItem appBarHelpMenuItem = new ApplicationBarMenuItem(AppResources.Help);
appBarHelpMenuItem.Click += new EventHandler(helpButton_Click);
ApplicationBar.MenuItems.Add(appBarHelpMenuItem);
}
But I can’t see the icon on app bar. What am I doing wrong?
I have test with this:
ApplicationBarIconButton helpButton = new ApplicationBarIconButton(new Uri("..//Images//appbar.questionmark.rest.png", UriKind.Relative))
But I get an invalid path exception. I’ve also changed UriKind to Relative, Absolute and with AbsoluteOrRelative.
appbar.questionmark.rest.png is marked as Resource, and copy to directory is set to “don’t copy”.
The pictures Build Action should be Content.
Try this i hope this will work.:)
This is how MSDN describes how to add a button to the AppBar
I think your problem is that your picture is set as a Resource and not as Content.