Wpf 用VB.net 3.5在VS2008中为DependencyProperty实现新的UIPropertyMetadata
在VB.NET3.5中使用VisualStudio2008。正在尝试从中实现排序解决方案 他的代码被转换成VB.netWpf 用VB.net 3.5在VS2008中为DependencyProperty实现新的UIPropertyMetadata,wpf,vb.net,Wpf,Vb.net,在VB.NET3.5中使用VisualStudio2008。正在尝试从中实现排序解决方案 他的代码被转换成VB.net 使用旧的IDE,我无法按给定方式使用它。我试图将函数转换为常规函数,但我不确定o和e来自何处 Public Shared ReadOnly CommandProperty As DependencyProperty = DependencyProperty.RegisterAttached("Command", GetType(ICommand), GetType(GridVi
使用旧的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未声明
且e未声明
。如何使用VS 2008将其转换为VB.net 3.5。谢谢。谢谢ASh的评论。我只需要正确地声明getFuncA并使用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
o
和e
应该是DependencyObject o,dependencPropertyChangedEventArgs e
-o
是一个依赖属性发生更改的对象,e
包含新旧值。DP变更事件由框架生成。getFuncA声明应类似于事件handler@ASh非常感谢。这正是我所缺少的。我还将getFuncA
更改为getFuncA
的地址。不理解UIPropertyMetadata
需要什么。
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