Hi I have been trying to convert a sample project written in C# to VB.NET, and I have successfully corrected most errors, bar the following two. Any tips on what the conversion should be would be appreciated:
The original C# code is as follows:
public event EventHandler<ExplorerErrorEventArgs> ExplorerError;
private void InvokeExplorerError(ExplorerErrorEventArgs e)
{
EventHandler<ExplorerErrorEventArgs> handler = ExplorerError;
if (handler != null) handler(this, e);
}
public ExplorerTreeView()
{
Loaded += (s, e) => InitExplorer();
SelectedItemChanged += OnSelectedItemChanged;
AddHandler(TreeViewItem.ExpandedEvent, new RoutedEventHandler(OnItemExpanded));
AddHandler(TreeViewItem.CollapsedEvent, new RoutedEventHandler(OnItemCollapsed));
}
And the converted VB.NET code is here:
Public Event ExplorerError As EventHandler(Of ExplorerErrorEventArgs)
Private Sub InvokeExplorerError(e As ExplorerErrorEventArgs)
Dim handler As EventHandler(Of ExplorerErrorEventArgs) = ExplorerError
RaiseEvent handler(Me, e)
End Sub
Public Sub New()
Loaded += Function(s, e) InitExplorer()
SelectedItemChanged += OnSelectedItemChanged
[AddHandler](TreeViewItem.ExpandedEvent, New RoutedEventHandler(OnItemExpanded))
[AddHandler](TreeViewItem.CollapsedEvent, New RoutedEventHandler(OnItemCollapsed))
End Sub
The problem areas are:
Dim handler As EventHandler(Of ExplorerErrorEventArgs) = ExplorerError
which underlines ExplorerError with the error:
Public Event ExplorerError(sender As Object, e As ExplorerErrorEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Secondly:
Loaded += Function(s, e) InitExplorer()
produces the error:
Public Event Loaded(sender As Object, e As System.Windows.RoutedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
There are also error squiggles under s,e, and InitExplorer but I suspect there is a syntax problem with this whole line. InitExplorer() is a Sub with no parameters.
I have read a bunch of articles to try and get ideas but I have not come up with anything. Any tips would be greatly appreciated! Thanks in advance.