Tuesday, September 01, 2009
Tuesday, September 01, 2009 11:09:39 PM (GMT Daylight Time, UTC+01:00) (C# | General | Visual Studio | WPF)

I’m pretty sure that anyone who actually likes to ‘make stuff’ and has been a programmer at least once in their life – has got a short list of pet projects that he/she has started – and maybe even finished :-)

Here are a few of my ‘pets’.

CodeDom class generator for VS2005/2008

addin-screenshot_01This was an early attempt of mine at writing a Visual Studio Add-in - designed to create a class from a database query, table or stored procedure. There’s a ton of stuff like this out there – but I wanted something that generated the class from the DataTable – SchemaTable of an IReader – so that a class could be generated from any query or shape for use with DTOs, reporting, or a simple domain model. You can choose from C#, VB or C++ to generate the class as well as a number of styles of classes – from a built-in IReader constructor, attribute based mapper, or plain old CLR object (POCO). There also doesn’t have to be any data in the result set for this to work since the SchemaTable will be returned regardless.

 addin-screenshot_02

The Add-in also adds an ‘Open Folder’ option to the context menu of all solutions, projects, folders, etc. in Solution Explorer. This feature exists as of VS 2008 – but I wanted it at the top of the context menu – not at the bottom.

You can download the Add-in here at - FiftyEightBitsAddin.zip Just unzip and place the contents of the zip file into any one of the Add-in locations for VS2008.

 

PreCode Code Snippet Plugin for WLW

This is an open source project hosted at Codeplex – a plugin for Windows Live Writer that helps to format code snippets before pasting them into a blog post (or elsewhere). It was written for the excellent SyntaxHighlther from Alex Gorbatchev. It’s a WPF app – and also includes a standalone desktop version for pasting formatted code into any app (ideal for Stack Overflow). Please don’t look at this as a reference WPF app though – it’s more than just a little ‘hacky’. The app that follows is my ‘better’ WPF effort. Visit http://www.codeplex.com/precode for more details, the source code and the installer.

 precode_screenshot

 

Gallery Builder – Desktop and Web

If you follow the Photos link above – you’ll see the results of this application. Yet another gallery builder app – however I’ve spent a bit of time on this one – choosing a specific architecture that I think represents a good balance between desktop and web server processing for small to medium size collections of photos. I’ll be hosting a Wiki soon with docs and the full download including the HttpModule that is used display galleries online (along with a sample app and extensibility features). The module can be integrated into any site and includes full Atom and Rss syndication support, nested galleries, as well as good caching/304 response support.

 0.9.8.1000

A pre-release version of the desktop application can be downloaded from the link below (although it’s not a whole lot of good without the web component). Hand rolling a complete set of control templates for a custom theme in WPF was a great way to get to know the inside of WPF.

NOTE: If there are no other WPF apps on your machine – and this application is the first WPF application you start – the ‘cold’ loading time for a WPF app is very long. Subsequent application loading times are what you’d expect.

GalleryBuilder_0.9.9.1000.zip

 

Yet another Task Management App - DotNetTime

dnt_screenshot

Yet another task/project list manager; only I actually use this one. This is an ASP.Net Model View Presenter application (and hopefully my last Webforms app). I use this to track my own time working on projects or just to ‘monitor’ my own time in general. Implementing multi-language support was a good learning exercise – and until recently this had been my ‘workbench’ throw anything at it hobby app. Now that charting controls are available free from Microsoft – I’ll be adding some charts to the reporting page. Feel free to register and have a play – it’s very basic – but it does what I need. Be gentle too if you’re into web hackery– this was built before my formal introduction to the world of application security and so I wouldn’t be surprised at all if there were XSS or CSRF vulnerabilities (although there shouldn’t be any SQL injection weaknesses – he says).

http://www.58bits.com/dnt



| Comments [0] | | #  
Thursday, June 25, 2009
Thursday, June 25, 2009 7:17:09 AM (GMT Daylight Time, UTC+01:00) (C# | WPF)

Charles Petzold’s book, Applications = Code + Markup - received some critical press for not being very pretty. And it’s true that there’s a lot of text and code listings but (and as you’ll see below), he was methodical.

I recently wanted to upgrade a Windows Live Writer plug-in I’d written to use the Windows Presentation Framework (WPF) – instead of WinForms and a custom UI library.

However my first attempt to compile the application as a Class Library resulted in the following error…

“Library project file cannot specify ApplicationDefinition element”.

Thankfully I’d remembered the opening chapters of Charles’ book where he spent considerable time explaining the creation of the application class and initial window. The trick in this case is to remove the App.xaml file. You then need to create your own start-up class – like Program.cs – as shown below, and the application will compile fine as either a Windows Application or Class Library. In the example below extra parameters are passed to the constructor of the main window which is opened as a Dialog – and then checked for the DialogResult value when the window is closed.

public class Program : Application
{
    [STAThread]
    public static void Main()
    {
        var app = new Program();
        app.Run();
    }

    protected override void OnStartup(StartupEventArgs args)
    {
        base.OnStartup(args);

        var window = new PreCodeWindow(new PreCodeSettings(), PreCodeWindow.Mode.StandAlone);
        window.ShowDialog();
        if (window.DialogResult.HasValue && window.DialogResult.Value)
        {
            System.Diagnostics.Debug.WriteLine("OK");
            Clipboard.SetText(window.Code);
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("Not OK");
        }        
    }
}

The downside to this approach is that you no longer have an application level location for placing resource dictionaries and other shared objects - and so these will need to be placed in each window as required.



| Comments [1] | | #  
Thursday, July 31, 2008
Thursday, July 31, 2008 6:07:46 AM (GMT Daylight Time, UTC+01:00) (WPF)

Just like Josh Smith I was looking around for some pre-rolled themes for WPF, and wondered why there was so little activity in this area. I would have thought the ability to take a professional looking UI (adjusted to match an organization's in-house style) would be a popular approach for building new business applications.

wpftheme Although there's quite a bit of work involved in creating a complete set of control templates (for all the required controls; textboxes, dropdowns, checkboxes, tab controls, lists, splitters, scrollers etc.) it can  be done (and it's a great way to learn WPF - even if you only override a few). Included here is a screen shot from my 'learning' WPF application in which I created a nearly complete control template set from scratch - including a custom toolbar strip, and dropdown/context menu system. What's more I give the user some options on basic color themes and backgrounds - just like Windows Live Writer does.

Commercially available themes must surely be on the way. Maybe they're just waiting for WPF adoption to reach higher levels, or perhaps visual designer support to improve. I'd estimate that it would take about 20 person days to complete a full theme set - and that's with a good graphic designer working with a good WPF developer together to assemble the theme.



| Comments [5] | | #  
Friday, May 23, 2008
Friday, May 23, 2008 1:40:07 PM (GMT Daylight Time, UTC+01:00) (WPF)

Gallery.BuilderThere just aren't enough hours are there. Have just about managed to cobble together an improved looking skin for dasBlog. Will re-write my image gallery component soon with URI templates and hackable search engine friendly URLs.

The application I use to package up my images for delivery is called Gallery Builder (original) - and it's my WPF learning exercise. A hand-rolled set of control templates produced not a bad looking UI. Would love to write an effects control for generating the gallery cover image. Alas there may not be enough hours...    (click the image on the left to enlarge).



| Comments [0] | | #  
Monday, April 02, 2007
Monday, April 02, 2007 9:46:04 PM (GMT Daylight Time, UTC+01:00) (WPF)

For a while now I’ve wanted to build a small application that would take a set of images and generate a set of previews, thumbnails and metadata xml ‘sidecar’ files that I could upload to my blog (I have a gallery viewing ASP.Net control that reads the directory structure and displays the gallery - and yes I have rendered image on the fly using an HTTP handler and GDI.Net in the past – but I prefer to upload my photo albums as pre-generated packages). 

I figured this was a chance to crack the covers of my WPF book and build my first small WPF application.  I got there in the end – and I learned a LOT about WPF in the process. 

I used the WPF SDK Photo Viewer Demo as a starting point. This was just enough to get me going with a ListBox control and some special formatting using control templates, but there was still a long way to go. 

Here’s what I’ve learned from this relatively small exercise. 

  1. WPF window controls have a minimum width and minimum height property. As silly as this may sound, it took me a few minutes before I realised these existed; however they were important since I wanted my XAML layout to be liquid with a fixed right hand panel and canvas, and an expandable listbox. Setting a minimum width prevented the liquid layout from shrinking too far (like a good'ol CSS liquid design).

  2. I learned how to use the Grid, StackPanel, Canvas and DockPanel controls. You really have to crack these first before you can do anything useful in WPF – especially if you were expecting a fast start like Windows Forms will give you when it comes to dropping controls onto a form. Expression Blend helps – but I switched to XAML source to tweak the layout regularly. What’s more I could only get control events to ‘wire-up’ in my code behind files when I placed the event handler name in Expression Blend. Double clicking on the control in VS 2005 will not create the event handler in code for you. No doubt when Visual Studio Orcas is released this will change.

  3. Watch out for BitmapEffects in a list – or on any other element that occupies a large area of the window (like GroupBox controls). Here’s a couple of good links on performance in WPF: Maximizing Performance in WPF and Optimizing WPF Application Performance and specific to the BitmapEffect -Bitmap Effects Overview. Bitmap Effects render in software and the delay in maximizing the window and scrolling the ListBox was dramatic when BitmapEffects were attached to the list and other large window controls.

  4. Triggers in a ControlTemplate are awesome – but I wanted to apply a BorderBrush to a border that surrounded a ListBoxItem for the IsFocused trigger – and the Border control does not have a property trigger for IsFocused. Here’s how you do it from the ControlTemplate for the ListBoxItem:
     
    <Trigger Property="IsFocused" Value="True"> <Setter TargetName="ItemBorder" Property="Border.BorderBrush" Value="#FF8877BB"/> </Trigger>

    Once you’ve defined the triggers – you can set the property of any named control in the XAML control tree by setting the TargetName. It took me ages to work this out. I just named the Border that I’d placed around the template ‘ItemBorder’ and then set the trigger setter as followsJust to be clear, this is a trigger defined in the ControlTemplate for the ListBoxItem - but it is changing the property of another named control in the XAML mark-up; the Border control named ItemBorder. Way cool

  5. When viewing Thumbnails – don’t use the Thumbnail property of the BitmapImage or BitmapSource – it may not be oriented the same way as the full image if you have rotated the image (depending on the software you’ve used to rotate the image). Instead use the DecodePixelWidth of the BitmapImage when you open the file and give it a decent size for thumbnails. I kept the Zoom feature of the SDK sample app – but modified it to give my ListItemControl template a rectangular shape. Having larger resolution thumbnails to back up the Zoom feature meant that this was now a useful method for selecting images without necessarily having to open a larger preview window.

  6. The world of binding – I learned a lot about binding including binding property values of one control to the values of another (the Zoom effect). I also learned something very useful from this blog post on how to get the PlacementTarget for a context menu click from this entry… Binding ContextMenu to its logical Parent.

  7. Although there’s a ton of glassy button effects out there – I found this link very helpful in getting an animated glassy effect for my apps buttons – Creating a Glass Button: The Complete Tutorial. A great intro to Storyboards and Animations.

And here’s the result..(click on the image for a larger version).

My First WPF App



| Comments [1] | | #  

search

categories

on this page

ads

archive

Total Posts: 95
This Year: 1
This Month: 0
This Week: 0
Comments: 80