Help with converting C# code to VB .NET

Vyyk_Drago
Vyyk_Drago used Ask the Experts™
on
Hi,

Iam learning wpf using vb.net and am working through a tutorial on the Ribobn control UI element.  I have the turorial here but the code here is in C#.

http://www.uxpassion.com/2008/11/how-to-use-add-ribbon-to-wpf-applications-part-3/

Can someone please help me on how to implement this small bit using VB.NET - this is what I have so far, but I keep getting the error saying OnCanExecute is not member of testapp.testapp.Window1.

Any help will be much appreciated.

Thanks
V
Imports System
Imports System.IO
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports Microsoft.Windows.Controls.Ribbon
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation
Imports System.Collections.ObjectModel

Imports System.Windows.Input


Class Window1

    Private Sub OnCanExecute(ByVal target As Object, ByVal args As CanExecuteRoutedEventArgs)

    End Sub

End Class

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008

Commented:
Where are you getting that error?  

OnCanExecute is a private method, and not accessible outside of the Window1 class:

     Private Sub OnCanExecute
Try this:
1. Imports System
   2. Imports System.IO
   3. Imports System.Net
   4. Imports System.Windows
   5. Imports System.Windows.Controls
   6. Imports Microsoft.Windows.Controls.Ribbon
   7. Imports System.Windows.Data
   8. Imports System.Windows.Media
   9. Imports System.Windows.Media.Animation
  10. Imports System.Windows.Navigation
  11. Imports System.Collections.ObjectModel
  12. Imports System.Windows.Input
  13.
  14.
  15. Namespace RibbonTutorial
  16.     Public Partial Class Window1
  17.         Public Sub New()
  18.             Me.InitializeComponent()
  19.         End Sub
  20.        
  21.         Private Sub OnCanExecute(ByVal target As Object, ByVal args As CanExecuteRoutedEventArgs)
  22.             args.CanExecute = True
  23.         End Sub
  24.        
  25.         Private Sub OnShowClipboardGroup(ByVal target As Object, ByVal args As CanExecuteRoutedEventArgs)
  26.             MessageBox.Show("This is the Clipboard!.", "Clipboard Dialog")
  27.         End Sub
  28.     End Class
  29. End Namespace

Open in new window

Author

Commented:
Hi nandithaa,

That works excellently except for a small typo where

Private Sub OnShowClipboardGroup(ByVal target As Object, ByVal args As CanExecuteRoutedEventArgs)

should probably read

Private Sub ListGlobalNamesCommand(ByVal target As Object, ByVal args As ExecutedRoutedEventArgs)

Much appreciated :)
Thanks
V

Author

Commented:
Small typo, but on the whole very clear and useful.
Thanks :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial