WPF Icon and Uri

后端 未结 1 1478
孤街浪徒
孤街浪徒 2021-01-24 19:07

I am trying to load an icon that is in my project directly in the main directory. In order to do that i do this:

Dim uriSrc As Uri = New Uri(\"pack://ELE100Walke         


        
1条回答
  •  野的像风
    2021-01-24 19:41

    pack://ELE100WalkerWPF:... is not a valid Pack URI.

    You can also not set a BitmapImage's UriSource property without calling BeginInit and EndInit. Use the BitmapImage constructor that takes an Uri argument.

    Provided that ShowMCF.png is located in the top level folder of your Visual Studio Project, and its Build Action is set to Resource, this should work:

    Dim uri As Uri = New Uri("pack://application:,,,/ShowMCF.png")
    Dim bitmapImage As BitmapImage = New BitmapImage(uri)
    

    If the image resource is in a referenced assembly (called ELE100WalkerWPF), you must included the assembly name like this:

    Dim uri As Uri = New Uri("pack://application:,,,/ELE100WalkerWPF;component/ShowMCF.png")
    Dim bitmapImage As BitmapImage = New BitmapImage(uri)
    

    0 讨论(0)
提交回复
热议问题