Code Snippet Manager in C# and WPF

Hello all, today I will post a simple code snippet manager created using C# and WPF. The idea of the app is to be used when making presentations and you need to paste all kind of code snippets (html, xaml, C#, java ). The similar tool is used by Karen Corby in MIX09 presentation about creating silverlight controls.
This is my first .net application so you will see all kind of C# strangeness like using "Object" instead of "object" and String instead of "string".
Because this was my first application I choose to use WPF not WinForms because WinForms is a lot like Swing and I've wanted to see "how declarative XML for the UI is better" and I can say: "hmm ok there is some big pluses". Anyway I have little experience with Flex's MXML too and if you ask me the MXML is a lot than XAML.
The code snipper manager application lokks like this :
The view is very simple and I can say that XAML is perfect for creating a simple views and there is tones of snippets in internet for all kinds of examples like popup for example.

The application XAML looks like this :

<Window x:Class="CodeSnippetManager.Window1"
Title="Snipper Manager" Height="355" Width="177" Topmost="True" ResizeMode="NoResize" >
<Grid Height="309">
<ListBox Margin="0,-8,0,38" Name="listSnippets" HorizontalContentAlignment="Left"
SelectionMode="Single" SelectionChanged="listSnippets_SelectionChanged"

<Popup Placement="Mouse" Name="popupHint" HorizontalAlignment="Left"
VerticalAlignment="Top" IsOpen="False" AllowsTransparency="True">
<Border BorderBrush="Black" BorderThickness="1">
<Grid Background="White">
<TextBlock Background="White"

<WrapPanel Height="40" Name="wrapPanel1" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button Height="26" Name="menu" Width="65" Margin="5" Click="menu_Click">Menu</Button>
<Button Height="26" Name="clear" Width="65" Margin="5" Click="new_Click">Clear</Button>

Maybe you can notice that code is short and very simple, maybe simpler than MXML in Flex and a lot simpler than Swing/SWF and JavaFX. There is no code fragments on the view and etc. But what i did not understand is why all kinds of Name x:Name and other attributes are needed. The XML schemas are strangely organized if you ask me.
Anyway the project is uploaded here You can download the source and edit it if you want or you can download the release version and try to use it.
The application have the fallowing features:
- creating and adding code snippets from the clipboard
- saving sets of snippets as XML files for usage in the future
- loading sets of snippets
- delete snippet if it is inserted by mistake
Maybe you will notice strange fonts rendering ( there is no clear type ). This is because WPF 3.5 doesnt support clear type at this moment. But clear type will be supported in the incoming .net 4.0 release. If you ask me the current fonts looks even bad than the Java Swing font rendering before 1.6 update 10 which is funny.
The Expression Blend application is written in WPF too and the fonts looks also this bad but if you use dark theme (black by default) it is harder to notice the bad looking fonts. So if you want change the application color schema to darker. I will add dark theme when I have time.
The reason why I've created this app is because I often need to write code in front of the students when I make presentations and I think that using a tool like this decrease the possibility to make mistakes when writing.
The idea of this app came after I watch the Karen Corby presentation in MIX09 called Building Microsoft Silverlight Controls btw you can watch it here . But because I was unable to find this app I've created my own.

Share this:


Superhero with Java powers && Gamer && (Sci-Fi & Star Wars geek) && Bulgarian Java User Group Leader && nerds2nerds podcaster && (link: guy ? this : null


Anonymous said...

that is a silly comparison. Use javaFx instead if you want to compare it with Java technology.

jNayden said...

Heh :) Ok maybe I will but the target is different.

I am making normal regular not animated application so I dont need JavaFX for it. But ok Maybe I will make demo in JavaFX

Sara Reid said...

Code snippets in Visual Studio are small parts of written code that can be inserted using a specific shortcut again and again in applications. In this post I will demonstrate how to use them through an example.

Suppose you find yourself writing the code below again and again in your application:
if (SomeObject!=null)
Do this
Do the other

Then it is nice if you could create a snippet in visual studio and whenever you need this code, insert it automatically through a sequence of keyboard/mouse shortcuts.


jNayden said...

Yes thats true but I am not a windows programmer so I have no idea how to add a OS hook from C# which responds to some key/mouse combination. Anyway the tool is free opensource the source code is very small so if you want you can add it. Maybe I will add feature like this in Swing version of the app ( ) because I have idea how to do this in Java but in C# ( where is easier I dont know how :) )

Rahul said...


First of all. Thanks very much for your useful post.

I just came across your blog and wanted to drop you a note telling you how impressed I

was with the information you have posted here.

Please let me introduce you some info related to this post and I hope that it is useful

for .Net community.

There is a good C# resource site, Have alook