Search
Thursday, November 20, 2008 ..:: Blendblog.net ::.. Register  Login
 Bloggers Minimize

 Print   
 Sponsors Minimize

 Print   
 Users Online Minimize
Membership Membership:
Latest New User Latest: areel
New Today New Today: 0
New Yesterday New Yesterday: 0
User Count Overall: 15

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

Online Now Online Now:

 Print   
 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!


 Print   
 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

Your name:
Title:
Comment:
Add Comment   Cancel 

  
 Search Minimize

 Print   
 Archive Minimize

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




Submit Survey  View Results

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