How do I use an icon that is a resource in WPF?

前端 未结 5 499
北荒
北荒 2020-11-29 20:06

I have a .ico file that is embedded as a resource (build action set to resource). I am trying to create a NotifyIcon. How can I reference my icon?

notifyIc         


        
5条回答
  •  一整个雨季
    2020-11-29 21:01

    Well, you don't want to use the resx style resources: you just stick the ico file in your project in a folder (lets say "ArtWork") and in the properties, set the Build Action to "Resources" ...

    Then you can reference it in XAML using PACK URIs ... "pack://application:,,,/Artwork/Notify.ico"

    See here: http://msdn.microsoft.com/en-us/library/aa970069.aspx and the sample

    If you want to be a little bit more ... WPF-like, you should look into the WPF Contrib project on CodePlex which has a NotifyIcon control which you can create in XAML and which uses standard WPF menus (so you can stick "anything" in the menu).

提交回复
热议问题