How to reference image resources in XAML?

后端 未结 4 1112
轮回少年
轮回少年 2020-11-28 22:08

I put an Image control on a Window and I would like to display an image that is stored in a project resource file named \"Resources.resx\". The name of the imag

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 22:36

    If the image is in your resources folder and its build action is set to Resource. You can reference the image in XAML as follows:

    "pack://application:,,,/Resources/Search.png"
    

    Assuming you do not have any folder structure under the Resources folder and it is an application. For example I use:

    ImageSource="pack://application:,,,/Resources/RibbonImages/CloseButton.png"
    

    when I have a folder named RibbonImages under Resources folder.

提交回复
热议问题