When I was using WinForms I was using ListBox with overridden OnDrawItem to customize look. Now I wanted to create the same form in WPF. I realized that WPF ListBox does not have OnDrawItem method so it has to be done another way. Here is part of my code of CustomListBox, which I used in WinForms:
Namespace Toolset.Controls
Public Class CustomDrawListBox
Inherits ListBox
Dim _1 As Icon = My.Resources._1
Public Sub New()
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
Me.ItemHeight = 16
End Sub
Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
e.DrawBackground()
If e.Index >= Me.Items.Count OrElse e.Index <= -1 Then
Return
End If
Dim item As Object = Me.Items(e.Index)
If item Is Nothing Then
Return
End If
Dim text As String = item.ToString()
Dim stringSize As SizeF = e.Graphics.MeasureString(text, Me.Font)
If DTun4.Form1.status.ContainsKey(text) Then
If DTun4.Form1.status(text).status = 0 Then
e.Graphics.DrawIcon(_0, 0, e.Bounds.Y)
e.Graphics.DrawString(text, Me.Font, New SolidBrush(Color.Red), New PointF(20, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2))
e.Graphics.DrawString("999", Me.Font, Brushes.Red, New PointF(e.Bounds.Right - 25, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2))
ElseIf DTun4.Form1.status(text).status = 1 Then
e.Graphics.DrawIcon(_1, 0, e.Bounds.Y)
e.Graphics.DrawString(text, Me.Font, New SolidBrush(Color.YellowGreen), New PointF(20, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2))
e.Graphics.DrawString("N/A", Me.Font, Brushes.YellowGreen, New PointF(e.Bounds.Right - 25, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2))
....rest of long code....