/
Window1.xaml.vb
66 lines (54 loc) · 2.09 KB
/
Window1.xaml.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Imports DevExpress.Xpf.Grid
Imports System
Imports System.Collections.ObjectModel
Imports System.Windows
Imports System.Windows.Media.Imaging
Namespace UnboundColumnWithIcons_CodeBehind
Public Partial Class Window1
Inherits Window
Private dataSource As ObservableCollection(Of MyObject)
Public Sub New()
Me.InitializeComponent()
dataSource = New ObservableCollection(Of MyObject)()
dataSource.Add(New MyObject("cut"))
dataSource.Add(New MyObject("copy"))
dataSource.Add(New MyObject("paste"))
dataSource.Add(New MyObject("delete"))
Me.grid.ItemsSource = dataSource
End Sub
Private Sub GridControl_CustomUnboundColumnData(ByVal sender As Object, ByVal e As GridColumnDataEventArgs)
If Equals(e.Column.FieldName, "IconUnbound") Then
If e.IsGetData Then
Dim row As MyObject = dataSource(e.ListSourceRowIndex)
Dim resourceName As String = GetResourceName(row.Action)
e.Value = GetImage(resourceName)
End If
End If
End Sub
Private Function GetImage(ByVal resourceName As String) As BitmapFrame
Dim uri As Uri = New Uri("pack://application:,,,/Icons/" & resourceName, UriKind.Absolute)
Return BitmapFrame.Create(uri)
End Function
Private Function GetResourceName(ByVal action As String) As String
Select Case action
Case "copy"
Return "copy32x32.png"
Case "cut"
Return "cut32x32.png"
Case "delete"
Return "delete32x32.png"
Case "paste"
Return "paste32x32.png"
End Select
Return String.Empty
End Function
End Class
Public Class MyObject
Public Sub New()
End Sub
Public Sub New(ByVal action As String)
Me.Action = action
End Sub
Public Property Action As String
End Class
End Namespace