我有一个 ListView,每行应该包含一个图像和文本。文本的绑定工作正常,但没有显示图像。
我的 XAML 标记:
<ListView Name="lvUpgrade">
<ListView.View>
<GridView>
<GridViewColumn Width="20px">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Path=Icon}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="75px" DisplayMemberBinding="{Binding Path=Time, StringFormat={}{0:HH:mm:ss}}" />
<GridViewColumn Width="300px" Header="Nachricht" DisplayMemberBinding="{Binding Path=Message}" />
</GridView>
</ListView.View>
</ListView>
我背后的代码:
Public Class Upgrade
Public Sub AddMessage(ByVal message As Message)
Me.lvUpgrade.Items.Add(message)
End Sub
Public Class Message
Public Enum MessageType
Normal
Information
Warning
[Error]
End Enum
Public Sub New(ByVal type As MessageType, ByVal message As String)
_Type = type
_Message = message
End Sub
Private _Type As MessageType = MessageType.Normal
Public ReadOnly Property Type As MessageType
Get
Return _Type
End Get
End Property
Private _Message As String = String.Empty
Public ReadOnly Property Message As String
Get
Return _Message
End Get
End Property
Private _Time As DateTime = Now
Public ReadOnly Property Time As DateTime
Get
Return _Time
End Get
End Property
Public ReadOnly Property Icon As System.Drawing.Image
Get
Select Case Me.Type
Case MessageType.Information
Return My.Resources.Information16
Case MessageType.Warning
Return My.Resources.Alert16
Case MessageType.Error
Return My.Resources.Error16
Case Else
End Select
Return Nothing
End Get
End Property
End Class
End Class
为了绑定图像,我使用了一个从本地资源返回图像的属性。我使用与文本相同的方式将图像绑定到控件。这是尝试错误还是为什么不起作用?
感谢您的任何回复。