Button image not visible

北城以北 提交于 2019-12-12 02:57:22

问题


I'm trying to create a Windows 8.1 store app, and I need to add a button to it. The button should display an image.

  • I add the image to the assembly in Solution Exploreras Artwork/Pencil.png
  • I add the button to the UI
  • Using the property editor for the button, I select Foreground image.
  • The designer shows a list of available images from the assembly, I choose the image.
  • The designer shows the selected image (partially).
  • The button remains blank.

I tryied playing around with different content types (of the image), as Content, Embedded resource, Do not copy, Copy if newer.

The image is not visible either at design or run time.

I found tons of articles from 2005 to 2012 about this problem in WPF. Tryed to change the image source (although I think the designer should set it correctly):

  • Pencil.png
  • Artwork/Pencil.png
  • pack://siteoforigin:,,,/Pencil.png
  • pack://siteoforigin:,,,/Artwork/Pencil.png
  • pack://application:,,,/Pencil.png
  • pack://application:,,,/Artwork/Pencil.png

Any ideas?

To make the environment clear:

  • Visual Studio 2013 Update 2
  • Project type: Visual C#/Store Apps/Windows Apps/Blank App
  • Target: Windows 8.1

回答1:


It seems that the correct combination (to display an image on a Windows 8 app button) is:

  • set it as backbround image (as opposed to foreground)
  • set the file to be "PRIResource" (as opposed to "Embedded resource")
  • use the designer to specify the image (which will generate a reference like this "Artwork/Pencil.png")

:-( It works design-time, but it does not work runtime.




回答2:


Here's one that works both design-time and runtime:

  • set it as backbround image (as opposed to foreground)
  • set the file to be "Content", "Copy if newer"
  • use the designer to specify the image (which will generate a reference like this "Artwork/Pencil.png")


来源:https://stackoverflow.com/questions/24807740/button-image-not-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!