ePlaice / For the Best Software on the Net

Mainly Free and Open Source Software


WPF Navigation

SVG to XAML Conversion | Standalone WPF Applications | Silverlight 3 | Project Template for Silverlight 3 | Silverlight Libraries | XAML Introduction | WPF Data Binding | WPF Styles and Templates |

Valid XHTML 1.1

Latest news

20 Nov 2007: .NET Framework Version 3.5 released.

Links:

Standalone WPF Applications

Much attention has been focused on the the applicability of WPF (actually Silverlight WPF/E) to Net based applications. However, just as interesting, I find that WPF can bring a much richer experience to the desktop with its strong visual theme.

At the moment I am using SharpDevelop 3.0 (Beta 1 version) compile features to experiment with some of the ready made applications that I have found mainly on the CodeProject site. Eventually, my intention is to adapt all my NET 2.0 applications to use the new standard, but in the meantime I hope to learn a little bit about the main differences betwen using Windows Forms and Windows Presentation Foundation.

Basic Requirements

I found that all I needed to compile and run was the following :-

.NET Framework Version 3.0
.NET Framework Version 3.5 (required by SharpDevelop 3.0)
SharpDevelop 3.0 (Beta 1 version)

Current Limitations

The beta version of SharpDevelop does have a few limitations, primarily at the moment, you cannot fully design or view your window using the WPF tools library which contains buttons, textboxes, menubars etc. There are also no timescales as to when releases will happen, but there is a lot of activity, with new versions being released to the Build Server frequently. However being able to view a project and use the editor both for XAML and cs files is still very useful.

Some Features of WPF

Apart from its use of XAML which provides graphical and animation features to the design, WPF has other significant features which puts the development of applications which once demanded 'super' programmers within the reach of ordinary mortals.

XAML Graphics

The specification for XAML includes pre-defined shapes for an Ellipse, Line, Path, Polygon, Polyline and Rectangle. Each of the basic shapes have common properties including Stroke, Stroke Thickness and Fill. Shapes can be combined with one another to make more complex shapes so that it is possible to derive almost any shape using the basic building blocks. As an example if you want to draw a rectangle with a red outline, just place the following code using Notepad in a file with a suffix of .xaml.

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Rectangle Width="450" Height="150" Stroke="Red" StrokeThickness="5">
</Rectangle>
</Canvas>  

Now double click on the filename and provided you have .NET 3.0 installed you will see the shape in your default browser window. Of course the Microsoft plan is that you buy Expression Design which allows you to drag and drop shapes and controls onto a form and then automatically generate the XAML code. I have to admit to not having used this product and I certainly would not like to have to generate by hand the XAML code since you can soon find yourself needing to generate hundreds if not thousands lines of code. So an alternative that I have considered is to use a tool such as Inkscape to produce SVG and then run a conversion to XAML (see my notes on SVG to XAML conversion). I then used Inkscape to try to recreate the above example and although the end result was the same the coding was quite different as it used Path data to draw so it was nowhere near as intuitive. There are always alternatives so I began looking at the possibility of using Xamlpad.exe which comes with the NET 3.0 SDK - however, after considering downloading this massive library for all of two seconds, I came across Kaxaml - see links. This does a really good job for simply viewing and editing XAML, and now in it's latest 1.0 version provides much improved editing thanks to use of the SharpDevelop editor including intellisense code completion, colour coding and many more enhancements. Now using SharpDevelop 3.0 alpha and Kaxaml you have quite a reasonable environment for developing WPF applications. Stop press - the latest SharpDevelop 3.0 build 2907 now displays a XAML form in the design view, at least it did for one form. There is also now a properties dialog that is displayed in design view allowing So it seems SharpDevelop is finally getting there.

XAML for Forms

Although it is still possible to call up NET 2.0 Windows Forms, you can use XAML to design forms. So in NET 3.0 we have the concept of Button, Checkbox, Combobox, Testbox, Menu to mention just a few. It looks like SharpDevelop 3.0, when it is developed will allow you to select one of these tools and drop them on a form in a similar way to that currently possible in SharpDevelop 2.0. The big difference is that here the Form will be totally specified by XAML. At the moment it seems that the NET 2.0 data components such as Datagridview are not part of the NET 3.0 XAML specification, but they can be made use of in code. I need to do a bit more research to see which way this is going before I jump to conclusions.

Electronic Paper

As part of WPF Microsoft has released new document technology called XPS (XML Paper Specification) which is aimed at providing a consistent appearance for documents regardless of the environment. To me it seems to be aimed at the market currently dominated by the Adobe Acrobat PDF specification, but to be honest I haven't looked at this area too much. I tried a few sample applications but either I wasn't impressed or not too interested - do you really want to see the pages curl when you turn over a page? If that impresses you then you may be interested in looking further.

Data Binding

I am keen on all things data and as all the design experts say, always try to separate the data from the procedural code, in such a way that a change to the code does not impact on the data. If the data and code are entangled in an application then it becomes exceedingly difficult to have any re-use of the data in another application; so when the successor to WPF comes along you are not into a major rewrite. WPF re-introduces the concept of data binding where traditionally a database field is bound to a text box on a Windows form. This implies a fairly static situation where the fields from the database are hardwired to the textbox fields on the screen and the only way they can change is by trawling through the database and presenting a different record on the screen. With WPF this is taken several steps further because now you can have a database changing independently of your application and have your screen being updated in realtime by the changes. For example your database could contain share prices being updated continuously which are then displayed in textboxes on your screen. WPF allows these textboxes to be bound to the database and to change in real time without any screen refreshes. Another common application is where the user can have a control which dynamically changes the display of a graph similar to the type of user controls in current Paint.NET, but this time you don't change a set of parameters, press the OK button and wait for the screen to refresh; instead you use sliders (say) to change the parameters and watch the screen change as you move the slider.

Some Sample Applications

Paint.NET was the first application that raised my interest in .NET because prior to this I had sort of regarded .NET as a bit of a gimmick that might not necessarily catch on. However, when I started to look at C#, the managed code features and the nice looking applications that could be developed using a ready made library, I saw parallels with Delphi. Only this time the applications seemed very robust if only a little bit less rapid to develop. I decided to learn from some sample applications and try some fairly simple NET 3.0 applications, just using the beta version of SharpDevelop 3.0 and manually editing the XAML code. At one stage there was talk of Paint.NET being redeveloped for NET 3.0/3.5 but now it seems firmly anchored in the NET 2.0 environment, so maybe we will see this in Paint.NET 4.0?

HBarChart

This is a really well executed Bar Chart demonstrating all the good things you can do in .NET (actually this does not need WPF, so I will move it to the NET 2.0 section). It is also very easy to use by adding your own bars and there is now even a simple DataSource. You can find it on the CodeProject.

WPF Diagram Designer

Like many of the WPF examples I found this on the CodeProject website. The application has a toolbox of symbols including Flowchart symbols and you can drag and drop them on the canvas and use arrow connectors to link them. The CodeProject article gives a detailed description of how the application is built and includes full source code so that you can use SharpDevelop to compile. The end result is a professional looking Diagram Designer which demonstrates many of the WPF graphical properties.

WPF C# Ribbon Control Library

Use this library to build applications with ribbon controls as in Microsoft Office. Just a point - check out the licencing issues to make sure there are no licencing problems if you want to develop a commercial application using this library.

Miscellaneous

Vshost.exe What is it?

Some of the applications I looked at had curious file suffixes vshost.exe and vshost.exe.manifest in the output debug directory. These are debugging aids for Visual Studio 2005, so as I don't use Visual Studio I always delete them. SharpDevelop does not create these type of files.

Pdb Files

SharpDevelop 3 does produce .pdb (Program Database files) files which are used for debugging purposes. There are some viewers available to look at these, but so far I haven't spent time on this.

WPF A Beginners Guide - In n Parts (by Sacha Barber)

Before you try anything serious in WPF then I would recommend you have a read of this excellent series detailed on the CodeProject. Most of what I have learnt has come from this source and the examples are excellent.