使用 Visual Studio 2008 和 VB.net 3.5。尝试从 [WPF] 实现排序解决方案 单击列标题时自动对网格视图进行排序 作者:Thomas Levesque
他的代码被 converter.telerik.com 转换为 VB.net
Public Shared ReadOnly CommandProperty As DependencyProperty = DependencyProperty.RegisterAttached("Command", GetType(ICommand), GetType(GridViewSort), New UIPropertyMetadata(Nothing, Function(o, e)
Dim listView As ItemsControl = TryCast(o, ItemsControl)
If listView IsNot Nothing Then
If Not GetAutoSort(listView) Then
' Don't change click handler if AutoSort enabled
If e.OldValue IsNot Nothing AndAlso e.NewValue Is Nothing Then
listView.[RemoveHandler](GridViewColumnHeader.ClickEvent, New RoutedEventHandler(AddressOf ColumnHeader_Click))
End If
If e.OldValue Is Nothing AndAlso e.NewValue IsNot Nothing Then
listView.[AddHandler](GridViewColumnHeader.ClickEvent, New RoutedEventHandler(AddressOf ColumnHeader_Click))
End If
End If
End If
End Function))
使用旧的IDE,我不能按给定的方式使用它。我尝试将该函数转换为常规函数,但我不确定o
和e
来自哪里。
Public Shared ReadOnly CommandProperty As DependencyProperty = DependencyProperty.RegisterAttached("Command", GetType(ICommand), GetType(GridViewSort), New UIPropertyMetadata(Nothing, getFuncA))
Public Shared Function getFuncA(ByVal o As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim listView As ItemsControl = TryCast(o, ItemsControl)
If listView IsNot Nothing Then
If Not GetAutoSort(listView) Then
' Don't change click handler if AutoSort enabled
If e.OldValue IsNot Nothing AndAlso e.NewValue Is Nothing Then
listView.[RemoveHandler](GridViewColumnHeader.ClickEvent, New RoutedEventHandler(AddressOf ColumnHeader_Click))
End If
If e.OldValue Is Nothing AndAlso e.NewValue IsNot Nothing Then
listView.[AddHandler](GridViewColumnHeader.ClickEvent, New RoutedEventHandler(AddressOf ColumnHeader_Click))
End If
End If
End If
End Function
编译器错误o is not declared
和e is not declared
。如何使用VS 3.5将其转换为 VB.net 2008。谢谢。
感谢 ASh 评论。我只需要正确声明getFuncA并使用AddressOf getFuncA
Public Shared ReadOnly CommandProperty As DependencyProperty = DependencyProperty.RegisterAttached("Command", _
GetType(ICommand), _
GetType(GridViewSort), _
New UIPropertyMetadata(Nothing, AddressOf getFuncA))
Public Shared Function getFuncA(ByVal o As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim listView As ItemsControl = TryCast(o, ItemsControl)
If listView IsNot Nothing Then
If Not GetAutoSort(listView) Then
' Don't change click handler if AutoSort enabled
If e.OldValue IsNot Nothing AndAlso e.NewValue Is Nothing Then
listView.[RemoveHandler](GridViewColumnHeader.ClickEvent, _
New RoutedEventHandler(AddressOf ColumnHeader_Click))
End If
If e.OldValue Is Nothing AndAlso e.NewValue IsNot Nothing Then
listView.[AddHandler](GridViewColumnHeader.ClickEvent, _
New RoutedEventHandler(AddressOf ColumnHeader_Click))
End If
End If
End If
End Function