2011-12-10 24 views
0

私はWindows Phone 7.1アプリケーションを開発しています。相対パスまたは絶対パスの混乱

私は次のフォルダ構造を持っている:

- Images (**folder**) 
    | 
    - appbar.questionmark.rest.png 

- Views(**folder**) 
    | 
    - About.xaml 

- MainPage.xaml 

...

を私はプログラム的にアプリバーを作成しようとしています:

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); 
    } 

しかし、私は見ることができませんアプリケーションバーのアイコン。私は間違って何をしていますか?

私はこれでテストを持っている:

ApplicationBarIconButton helpButton = new ApplicationBarIconButton(new Uri("..//Images//appbar.questionmark.rest.png", UriKind.Relative)) 

しかし、私は無効なパス例外を取得します。私はまた、UriKindをRelative、Absolute、AbsoluteOrRelativeに変更しました。をappbar.questionmark.rest.png

は「コピーしない」に設定されているリソースとしてマークされ、ディレクトリにコピーされます。

+0

最初に1つのポイントでこの行を試すことができます。 ApplicationBarIconButton helpButton =新しいApplicationBarIconButton(新しいUri( "..// Images // appbar.questionmark.rest.png"、UriKind.Relative));そして、あなたのPNGのプロパティを見てみる必要があります – BigL

+0

申し訳ありませんが、動作しません。 – VansFannel

+0

申し訳ありませんが、私の最初のコメントはあなたのコードからコピーしてすぐに入力して、それを編集しただけでは機能しません。 – BigL

答えて

0

写真のビルドアクションはコンテンツでなければなりません。

ApplicationBarIconButton helpButton = new ApplicationBarIconButton(new Uri("/Images/appbar.questionmark.rest.png", UriKind.Relative)); 

私はこれが働くことを願って、これを試してみてください。:)

をこれは私があなたの問題はあなたの写真がコンテンツとして資源とないように設定されていることだと思いますかMSDN describes how to add a button to the AppBar

ApplicationBarIconButton button1 = new ApplicationBarIconButton(); 
button1.IconUri = new Uri("/Images/YourImage.png", UriKind.Relative); 
button1.Text = "button 1"; 
ApplicationBar.Buttons.Add(button1); 

です。

+0

いいえ、動作しません。 – VansFannel

+0

これはうまくいきましたか? :) – BigL

+0

私はコンテンツとして画像を設定しているので動作します。どうもありがとう! – VansFannel

関連する問題