Pack URI and path not resolving image in WPF

前端 未结 3 662
梦如初夏
梦如初夏 2021-01-13 13:08

I have the following directory structure

Project
\\Images
 +view.png
control.xaml

and in the control I have a button defined by the followi

相关标签:
3条回答
  • 2021-01-13 13:25

    I actually got this to work, but had to set my source to "/ProjectName;component/images/view.png" Because I have the ProjectName as a referenced assembly this is then the same as the Path: portion at the msdn page that I referenced in the question.

    0 讨论(0)
  • 2021-01-13 13:30

    Xaml.VB

    Call the Image from Application folder and Design Page

    Private Sub LoadImages()
            Dim strUri As String
            strUri = AppDomain.CurrentDomain.BaseDirectory() & "\NavigationImages\settingsicon.png"
            Image2.Source = New BitmapImage(New Uri(strUri))
        End Sub
    

    Page load in Xaml.VB

    Call LoadImages()

    Xaml Design Page

    Image Name="Image2"Height="32" HorizontalAlignment="Left" 
    
    0 讨论(0)
  • 2021-01-13 13:45

    Set the Build Action for 'view.png' to Resource instead of Content and this problem should go away. I was able to reproduce your problem this way and it works correctly when set as a Resource.

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