对于声明性图像,您不需要 ms-appx 命名空间(在 XAML 中声明的图像)。对于动态数据绑定图像,会创建一个新的位图实例,并且它需要此命名空间。
解决此问题的一个好方法是从将命名空间实现为共享属性的基础对象派生数据对象:
Private Shared _baseUri As New Uri("ms-appx:'''")
'//image handling
Private _image As ImageSource
Private _imagePath As String
Public Property Image As ImageSource
Get
If Me._image Is Nothing AndAlso Me._imagePath IsNot Nothing Then
Me._image = New BitmapImage(New Uri(dataModelBase._baseUri, Me._imagePath))
End If
Return Me._image
End Get
Set(value As ImageSource)
Me._imagePath = Nothing
Me.SetProperty(Me._image, value)
End Set
End Property