2017-10-26 18 views
-1

VB.netでVisual Studio 2008を使用する3.5。与えられたとして、古いIDEを使用してconverter.telerik.comVB.netでVS 2008でDependencyPropertyの新しいUIPropertyMetadataを実装する

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)) 

によってVB.netに変換[WPF] AUTOMATICALLY SORT A GRIDVIEW WHEN A COLUMN HEADER IS CLICKED by Thomas Levesque

彼のコードからソートソリューションを実装しようとすると、私はそれを使用することはできません。私は関数を通常の関数に変換しようとしましたが、oeがどこから来たのか分かりません。

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 declarede is not declaredコンパイラエラー。 VS 2008を使ってこれをVB.net 3.5に変換するにはどうすればいいですか。ありがとう。

+1

'o'と' e'は 'のDependencyObject O、DependencyPropertyChangedEventArgs e'する必要がありますを使用していました新しい価値。 DP変更に関するイベントはフレームワークによって生成されます。 getFuncA宣言はikeイベントハンドラのように見えます – ASh

+0

@AShありがとうございました。それはまさに私が欠けていたものです。私は 'getFuncA'を' AddressOf getFuncA'に変更しました。 'UIPropertyMetadata'が必要としたものを理解していませんでした。 –

答えて

0

AShのコメントありがとうございます。 `o`は、依存関係プロパティが変更されたオブジェクトで、` e`が古い含まれています - 私はちょうど適切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 
関連する問題