I first published my C# WPF code snippets last December in this post. Due to increasing demand for VB versions of these snippets, I spent this past weekend porting them to VB. They are now available for both languages. You can download the snippet installer here.
Updated October 1, 2008:
I just updated the snippets to play nicely with the Strict option in VB. Grab the latest installer to get a version of the VB snippets that properly casts the result of the CLR get accessors based on the DP type.
All 65 snippets are supported in both C# and VB.NET now. The shortcuts for the VB versions are slightly different because the VB code editor does not provide the same level of support for snippets as the C# editor (see rant below).
In VB, for example, you cannot just type "dp" and hit tab twice to get a list of my dependency property snippets. Instead, you must type the entire unique shortcut (e.g., "dp2") and then hit tab to expand that specific snippet. It is probably easier to install all of the snippets within a single category (like "My Code Snippets") and then select the desired snippet from a list, as shown here:
I hope the VB snippets are helpful to a few of you! Let me know if you find any problems with the ported code.
Cheers,
Dr. WPF
Small Rant Regarding VB Snippet Support
In my earlier post, I talked about how I am looking forward to a day when Visual Studio code snippets will support more advanced macro-like functionality. After spending some time working with snippets in VB, I realize just how lucky I am to work primarily in C#. On a scale of Classic Pong to XBox 360, the C# snippet support is probably somewhere around a PS2, whereas the VB.NET snippet support is barely a Nintendo 64!
Come on, Microsoft… show a little love for that monster base of VB developers you created in the 90’s! At a minimum, at least give them snippet parity with C#. Here are a few of my complaints:
- Intellisense should provide snippet hints.
- The user should not have to tab through every field in the snippet… just the unique fields.
- There should be support for functions like ClassName().
- The $end$ tag should be supported.
- Pressing ‘Enter’ should take the snippet out of edit mode and place the cursor at the $end$ tag.
- If there are multiple snippets with the same shortcut, typing the shortcut should provide a filtered list of descriptions for the matching snippets.
Okay, I’m sure most VB developers know how to deal with all these limitations, and since I’m not really part of that constituency, my voice probably doesn’t hold much sway in this argument… so I’m done now. Enjoy the snippets!
what is Visual Basic? is it a programming language? LOL
Thanks a lot for the VB version!
Doc, I use your snippets so much…it has made me forget even how to write a DP by hand ;). Thanks so much for them!
I can’t say I do any VB (It gives me anxiety attacks looking at the syntax), but I’m sure theres plenty of developers out there that will surely appreciate these.
<sigh> It always annoys me to see even intelligent people whose blog I follow closely (Hi Marlon) react (even when LOL) sneer at VB. I seem to be one of the few "serious" developers (I have strong C/C++ background) that prefer the "weird" VB syntax.
Anyway, big Thanks to the good doctor for porting this to VB, even though it’s not your thing.
I am a VB dev, thanks a lot for your snippets!
Dear Doctor,
I also hope Microsoft will show a little love for VB programmers, and will follow your advices…
but in the EXACT OPPOSITE direction (<RotateTransform Angle="180" /> or <ScaleTransform ScaleX="-1" ScaleY="-1" ScaleZ="-1" />)
Copy and paste is the root of all evil, and a code snippet is the root of all evil taken to a new level.
It is a way to paste a piece of code without even the trouble to copy it.
VB Team, please spend your time giving us a decent scripting language (obviously Microsoft is fooling us with those IronRubyPython things)
VB Team, leave the code snippets unusable, leave those bad habits to C# programmers.
Wow _gdc! Strong feelings, eh?
So you reject my assertion in the earlier post that well designed snippets can help facilitate good coding practices around consistency and documentation? You’d rather have developers code from scratch each and every dependency property, routed event, and routed command? Not only does this seem like a waste of time, but it also seems prone to error and inconsistency across code files.
Oh well… to each his own. 🙂
@ _gdc
You wrote: "obviously Microsoft is fooling us with those IronRubyPython things"
I was still under the impression that the "script version" of VBx would be based upon the DLR, just like IronRuby and IronPython. Has
Sorry Doctor,
I hadn’t understood that you use your snippets…
I thought the medicine was only for the patients, I missed you drink it also 🙂
I really think I stressed too much the defects of repetition.
Please forget what I said and *do* use the snippets for better consistency.
Please forget what I said and *do* use the snippets for better documentation.
Please forget what I said and *avoid* wasting time manually inserting the same code over and over again.
Please forget what I said but *consider* working on a higher level of abstraction.
Please forget what I said but *consider* waiting for WPF to allow you to work on the correct level of abstraction.
Please forget what I said but *consider* using a code generator.
However, my main concern was about VB priorities:
On a scale of Classic Pong to XBox 360,
the VB snippet support PRIORITY is probably somewhere around a Nintendo 64,
whereas the VB scripting support PRIORITY is on the XBox 360 Premium-Universal-Enterprise-Ultimate-Edition
"I realize just how lucky I am to work primarily in C#. On a scale of Classic Pong to XBox 360, the C# snippet support is probably somewhere around a PS2, whereas the VB.NET snippet support is barely a Nintendo 64!"
..and snippet support for C++/CLI is…um…a collection of parts on the floor swept off the workbench after they made the first TI calculator. Badly done MS, badly done.
Dr. WPF,
WAY awesome!!! Thank you for sharing with us mortals!!
Cheers,
Karl
Glad to share, Karl! However, you won’t convince me you are mortal… mortals require sleep! 😀
What’s that Routed Helper Class? I think I need it very badly.
Hi Rico,
There are several helper classes in my snippets. These are classes that provide static helper methods to enable other snippets.
The general rule is that if you are using my routed event snippets, then you probably need to add the routed event helper class to your project. The same is true for using my routed command snippets… you will probably need the routed command helper class in your project.
Cheers,
-dw
Thanks for the VB Version. There is a very large base of developers that prefer the VB syntax, and VB even has some features of Linq that are not available in C#.
I have a dependency property problem on a user control that is driving me nuts – posted on MSDN WPF Forums (LumberPro), could you take a look and see if you see what I am doing wrong. Title is “DP Fails to Bind”.
Thank you.