Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 用VB.net 3.5在VS2008中为DependencyProperty实现新的UIPropertyMetadata_Wpf_Vb.net - Fatal编程技术网

Wpf 用VB.net 3.5在VS2008中为DependencyProperty实现新的UIPropertyMetadata

Wpf 用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

在VB.NET3.5中使用VisualStudio2008。正在尝试从中实现排序解决方案

他的代码被转换成VB.net


使用旧的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