Embed multiple icons in WPF EXE

前端 未结 5 836
后悔当初
后悔当初 2020-12-30 12:38

I have a WPF assembly in which I would like to embed five icons for different filetypes associated with my application. How can I embed these icons into my EXE?

@sm

5条回答
  •  半阙折子戏
    2020-12-30 13:25

    In addition to adding the files to your project resources, you can add the files to your project and set their Build Action to resource.

    You can then refer to the files from XAML using the Source property. For example a file Icon.png in a directory "Resources" would be loaded using:

    
    

    And to load the file from code you would use:

    new BitmapImage(new Uri(@"pack://application:,,,/Resources/Icon.png"))
    

提交回复
热议问题