相对或绝对路径混乱

发布于 2024-12-20 10:14:12 字数 1524 浏览 1 评论 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 被标记为资源,并且复制到目录设置为“不复制”。

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".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷你仙 2024-12-27 10:14:12

图片“构建操作”应该是“内容”。

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

尝试一下,我希望这会起作用。:)

这就是MSDN 描述了如何向 AppBar 添加按钮

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

我认为您的问题是您的图片被设置为资源而不是内容。

The pictures Build Action should be Content.

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

Try this i hope this will work.:)

This is how 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);

I think your problem is that your picture is set as a Resource and not as Content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文