.Net 4.0 Printing Made Easy – Part 0

When asked about printing, most developers will recoil in horror and rather avoid the topic. For some us though, we don’t have any choice but to tackle the problem full on. Luckily, in true .Net style, printing has become a much easier problem to take on. I recently undertook a large printing task that required designing and architecting a printing framework that could be used in a rich desktop application, allowing pretty much any control in the application (third-party or in-house), to be printable through a common print preview view complete with WYSIWYG page setup, headers / footers etc etc. Quite a task!

As usual there is a wealth of information on the web on the topic of printing, although I found most of it to be quite disparate and specialised with very few complete examples and gotchas. In this series of posts I intend to cover as many aspects of printing as possible to try and give a better understanding and concrete examples, as a kind of map through the printing underworld. To this end, this series of posts will spare the detail in favour of providing a more general end-to-end look at printing with links to greater detail for those that are interested.

In part 1 I will try to give a brief overview of printing in WPF and get you started with some code for getting hold of a list of local printers and what you can do with that information.

Silverlight 2.0 Elliptical Control 3D!

Well it has been a busy time for me since my last post, so this one took a little longer to get out. Fuelled by the launch of Silverlight 2.0 and my desire to give it another go (being a WPF developer I was a little put off by the bareness of 1.0) and set about finding a little project I could undertake to help me learn the ropes. I had several ideas (read, future blog posts!), but the most logical was to port the 3D ellipse control I wrote in WPF across to Silverlight 2.0. It was a fairly straightforward port and a real eye-opener to what the differences between Silverlight and WPF really mean.

The biggest challenge was the lack of the Media3D namespace. This prompted me to start building up a library of classes that aren’t included in Silverlight. So far I have created a Point3 (Point3D), Vector3 (Vector3D) and Quaternion (Quaternion). They are all basic implementations at the moment and contain just enough functionality to allow me to create the sample.

To overcome the lack of Viewport2DVisual3D, I calculate the scale for each child control based on it’s depth in the scene. This is a bit of a hack rather than a proper perspective correct transformation as I didn’t have the time to spend creating a camera implementation and setting everything up properly. Instead I make do with a camera focal length and combine that with the z value of each object to calculate how big it should appear on the screen, otherwise you wouldn’t be able to tell which controls are further away from the screen. Using a ScaleTransform ensures that the control appears correctly, but with a sense of depth.

Z-ordering is also taken care of, ensuring items deeper in to the scene appear underneath items which are closer to the screen. There are also a few little extras in there such as being able to animate the rotation of the ellipse, which when played around with can create some awesome effects.

The screenshot below shows the app running in full swing. Animation is enabled and a very small focal length is used, making the objects close to the camera appear much larger than those further back. There were around 200 buttons in the control at the time and it coped really well.

Continue reading

Updates + Book

I managed to get around to updating the sidebar this morning so that it is now a little more useful. This whole blogging thing has turned out much more simple and enjoyable than I first thought it would be.

I also decided to put a mention in for the book which I, along with two former colleagues, spent the last year writing, WPF Recipes in C# 2008: not for the money as we see very little out of it, but more so that people can get in touch with me in relation to its content.

We wrote the book in our evenings and weekends as an attempt to provide a collection of worked examples of various everyday problems, something we yearned for during our early days of using .Net 3.0. We hope it can help you avoid many of headaches we encountered on our WPF journey!

So be it questions, comments or corrections relating to the following chapters, get in touch.

  • 1 – Building and Debugging WPF Applications
  • 7 – Working with Text, Documents, and Printing
  • 10 – Working with 3D Graphics
  • 11 – Creating Animation

WPF Elliptical Layout Control – 3D!

After finishing my last post, WPF Elliptical Layout Control, I sat down and wondered what to do next. It occurred to me that creating a 3D carousel in WPF is a common question and one that doesn’t have all that many examples. A 3D control is also a natural progression from the 2D control and is not all that different. All we need to do is layout the objects in 2D, then rotate those points according to the orientation of the imaginary layout ellipse, taking in to account depth.

This example creates a new control which derives from FrameworkElement and is very similar to the implementation of the Viewport3D control. The new control overrides the measure and layout methods of FrameworkElement and positions the child controls (supplied as a collection of UIElements) according to the orientation of an imaginary 2D ellipse in 3D space.

It is assumed that the reader has some knowledge of custom controls, LINQ and 3D in WPF. The code provided is by no means an ideal implementation of the theory, it should be thought of more as a quick demonstration of the concept. And remember, in WPF there is almost always more than one way of doing the same thing, mine is just my take on the problem :0)

3D Elliptical Layout Panel Demo
3D Elliptical Layout Panel Demo

Continue reading

WPF Elliptical Layout Control

Today I was talking to a good friend and former colleague and he asked how I would go about laying out a collection of controls as if they were equally spread out around the edge of an ellipse. I did a quick Google and didn’t find much in the way of examples, so I decided to knock one together. An hour later and we have what I present here.

This is a fully working, but a little rough, demonstration of creating your own control and performing custom layout logic.

The demo in action

Continue reading

Welcomes and Hellos

Hello readers and welcome to my blog. I have been meaning to do this for a while now but have never gotten around to it, mostly because I know that I will actually have to come back and update this thing!

So a little about me. Well as the blog’s title suggests, I love to code! Presently I am working exclusively in .Net 3.5 and am an avid fan of WPF. I am currently working for SmithBayes where I have been working with .Net 3 (especially WPF) since the early CTP releases building a large decision making platform application.

The purpose of this blog is to be a place where I can share the knowledge in WPF I have gained over the years and get to know fellow .Net 3x fans.