Search
Saturday, May 19, 2012 ..:: Blendblog.net ::.. Register  Login
 Bloggers Minimize

  
 Sponsors Minimize

 Print   
 Users Online Minimize
Membership Membership:
Latest New User Latest: kappagus2
New Today New Today: 0
New Yesterday New Yesterday: 0
User Count Overall: 45

People Online People Online:
Visitors Visitors: 8
Members Members: 0
Total Total: 8

Online Now Online Now:

  
 Welcome to blendblog.net! Minimize

If you are a developer or designer who is creating cutting edge user interface experiences using Microsoft Expression Blend you've just found a great resource!  The purpose of this site is to share our experience with this brand new product.  As with any new piece of software there is a ton to discover.  Bugs will be revealed and workarounds discovered, hopefully this can be a resource to share in the discovery process!

While this site will focus largely on Expression Blend, it will also encompass WPF, Visual Studio, Silverlight, and other .net 3.5 technologies as they relate to the creation of great software.

Please login using your Microsoft LiveID or register a new account.  Doing so will let you comment on any of the blog entries on the site.  We look forward to helping you in your endeavors as well as you helping others in theirs!  We'd love to have more bloggers on our site...if you are interested please register and contact us!

Follow us:


  
 Setting up Routed Event Handlers in VB Minimize
Location: BlogsSean Cullinan    
Posted by: Sean Cullinan 11/29/2007 11:12 AM

I was working on custom tab items to go to the tab control.  I got some good sample code at Szymon Kobalczyk's blog but it was in C# and the project I'm working on is in VB.  Using the standard code translator tool at developer fusion I got pretty close to where I needed to be but got hung up on how to declare my routedEventHandler in VB.  The C# code was:

public event RoutedEventHandler CloseTab
        {
            add { AddHandler(CloseTabEvent, value); }
            remove { RemoveHandler(CloseTabEvent, value); }
        }

And the VB Code translated to:

Public Custom Event CloseTab As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
             [AddHandler](CloseTabEvent, value)
        End AddHandler
        RemoveHandler(ByVal value As RoutedEventHandler)
             [RemoveHandler](CloseTabEvent, value)
        End RemoveHandler
 End Event

Visual Studio then threw an error that stated "'RaiseEvent' definition missing for event 'CloseTab'.  All of the sample code I was finding on MSDN was in C# so no help there.  The blendaholic though pointed me to this article at the Karl on WPF blog that had an example of what I wanted to do.  As the error message suggests, in VB you have to have 3 sections to your custom event, an AddHandler, a RemoveHandler, and a RaiseEvent section.  So the actual code translation from C# is:

Public Custom Event CloseTab As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
             [AddHandler](CloseTabEvent, value)
        End AddHandler
        RemoveHandler(ByVal value As RoutedEventHandler)
            [ RemoveHandler](CloseTabEvent, value)
        End RemoveHandler
        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
             Me.RaiseEvent(e)
        End RaiseEvent
End Event

Hope this helps anyone else who is trying to figure out how to wireup routed event handlers in VB!

Permalink |  Trackback

Comments (6)   Add Comment
Re: Setting up Routed Event Handlers in VB    By marg on 5/13/2011 1:54 PM
Thanks so much! I was having the same problem with the same issues finding samples

Re: Setting up Routed Event Handlers in VB    By Tomas Cermak on 7/6/2011 9:16 PM
TGhank you SOOOO much. I was stuck on the SAME problem like you.

Question    By Tomas Cermak on 7/6/2011 9:33 PM
I was successful at displaying the closeable tab but if I click on "x" button, nothing happen. Probably some problem when registering close event? Would it be possible to post here the code in VB.NET of CloseableTabItem in VB.NET ? Thank you very much.

Re: Setting up Routed Event Handlers in VB    By John Hernandez on 11/8/2011 11:28 AM
Thanks so much. this helped a lot!

Re: Setting up Routed Event Handlers in VB    By replica watches on 12/19/2011 10:38 PM
Rolex:The leading name in luxury watches, <a href="http://www.replicawatch2u.com/rolex.html">replica rolex watches</a> has been the pre-eminent symbol of performance and prestige for over a century. Rolex mens and ladies <a href="http://www.replicawatch2u.com">REPLica WaTCheS</a> combine style and elegance with precision and reliability.<a href="http://www.replicawatch2u.com/rolex/daytona.html">rolex daytona replica watches</a>

Re: Setting up Routed Event Handlers in VB    By Max on 3/5/2012 4:11 PM
This helped!! THANK YOU! :)


Your name:
Title:
Comment:
Add Comment   Cancel 

  
 Search Minimize

  
 Archive Minimize

  
 Blendblog Survey Minimize
Our next client application will be written using:




Which Tablet Do you expect to buy?





Submit Survey  View Results

 Print   
Copyright 2011 by blendblog.net   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2012 by DotNetNuke Corporation