/
HeaderMenuHelper.vb
97 lines (83 loc) · 4.92 KB
/
HeaderMenuHelper.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Imports System
Imports System.Reflection
Imports System.Windows
Imports DevExpress.Xpf.Bars
Imports DevExpress.Xpf.PivotGrid
Namespace HeaderMenuCustomizationExample
Friend Class HeaderMenuHelper
#Region "AttachedProperties"
Public Shared ReadOnly AllowFieldSummaryTypeChangingProperty As DependencyProperty = DependencyProperty.RegisterAttached("AllowFieldSummaryTypeChanging", GetType(Boolean), GetType(HeaderMenuHelper))
Public Shared Sub SetAllowFieldSummaryTypeChanging(ByVal element As DependencyObject, ByVal value As Boolean)
element.SetValue(AllowFieldSummaryTypeChangingProperty, value)
End Sub
Public Shared Function GetAllowFieldSummaryTypeChanging(ByVal element As DependencyObject) As Boolean
Return CType(element.GetValue(AllowFieldSummaryTypeChangingProperty), Boolean)
End Function
Public Shared ReadOnly AllowFieldSummaryDisplayTypeChangingProperty As DependencyProperty = DependencyProperty.RegisterAttached("AllowFieldSummaryDisplayTypeChanging", GetType(Boolean), GetType(HeaderMenuHelper))
Public Shared Sub SetAllowFieldSummaryDisplayTypeChanging(ByVal element As DependencyObject, ByVal value As Boolean)
element.SetValue(AllowFieldSummaryDisplayTypeChangingProperty, value)
End Sub
Public Shared Function GetAllowFieldSummaryDisplayTypeChanging(ByVal element As DependencyObject) As Boolean
Return CType(element.GetValue(AllowFieldSummaryDisplayTypeChangingProperty), Boolean)
End Function
Public Shared ReadOnly AllowPopupMenuCustomizationProperty As DependencyProperty = DependencyProperty.RegisterAttached("AllowPopupMenuCustomization", GetType(Boolean), GetType(HeaderMenuHelper), New FrameworkPropertyMetadata(False, New PropertyChangedCallback(AddressOf OnAllowPopupMenuCustomization)))
Public Shared Sub SetAllowPopupMenuCustomization(ByVal element As DependencyObject, ByVal value As Boolean)
element.SetValue(AllowPopupMenuCustomizationProperty, value)
End Sub
Public Shared Function GetAllowPopupMenuCustomization(ByVal element As DependencyObject) As Boolean
Return CType(element.GetValue(AllowPopupMenuCustomizationProperty), Boolean)
End Function
#End Region ' AttachedProperties
#Region "PivotPopupMenuCustomization"
Public Shared Sub OnAllowPopupMenuCustomization(ByVal o As DependencyObject, ByVal args As DependencyPropertyChangedEventArgs)
Dim pivotGrid As PivotGridControl = TryCast(o, PivotGridControl)
If pivotGrid Is Nothing Then
Return
End If
If CType(args.NewValue, Boolean) = True AndAlso CType(args.OldValue, Boolean) = False Then
AddHandler pivotGrid.PopupMenuShowing, AddressOf pivotGrid_PopupMenuShowing
ElseIf CType(args.NewValue, Boolean) = False AndAlso CType(args.OldValue, Boolean) = True Then
RemoveHandler pivotGrid.PopupMenuShowing, AddressOf pivotGrid_PopupMenuShowing
End If
End Sub
Private Shared Sub pivotGrid_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
If e.MenuType = PivotGridMenuType.Header Then
Dim pivot As PivotGridControl = CType(sender, PivotGridControl)
Dim field As PivotGridField = e.GetFieldInfo().Field
If Convert.ToBoolean(field.GetValue(HeaderMenuHelper.AllowFieldSummaryTypeChangingProperty)) Then
e.Customizations.Add(CreateBarSubItem("Summary Type", "SummaryType", field))
End If
If Convert.ToBoolean(field.GetValue(HeaderMenuHelper.AllowFieldSummaryDisplayTypeChangingProperty)) Then
e.Customizations.Add(CreateBarSubItem("Summary Display Type", "SummaryDisplayType", field))
End If
End If
End Sub
#End Region
#Region "CustomBarItemsCreation"
Private Shared Function CreateBarSubItem(ByVal displayText As String, ByVal propertyName As String, ByVal field As PivotGridField) As BarSubItem
Dim barSubItem As New BarSubItem()
barSubItem.Name = "bsi" & propertyName
barSubItem.Content = displayText
Dim [property] As PropertyInfo = GetType(PivotGridField).GetProperty(propertyName)
For Each enumValue As Object In System.Enum.GetValues([property].PropertyType)
Dim checkItem As New BarCheckItem()
checkItem.Name = "bci" & propertyName & enumValue.ToString()
checkItem.Content = enumValue.ToString()
checkItem.IsChecked = Object.Equals([property].GetValue(field, New Object(){}), enumValue)
checkItem.Tag = New Object() { field, [property], enumValue }
AddHandler checkItem.ItemClick, AddressOf itemClickEventHandler
barSubItem.ItemLinks.Add(checkItem)
Next enumValue
Return barSubItem
End Function
Private Shared Sub itemClickEventHandler(ByVal sender As Object, ByVal e As ItemClickEventArgs)
Dim barItem As BarItem = TryCast(sender, BarItem)
Dim barItemInfo() As Object = CType(barItem.Tag, Object())
Dim field As PivotGridField = CType(barItemInfo(0), PivotGridField)
Dim [property] As PropertyInfo = CType(barItemInfo(1), PropertyInfo)
Dim newValue As Object = barItemInfo(2)
[property].SetValue(field, newValue, New Object(){})
End Sub
#End Region ' CommonMethods
End Class
End Namespace