Tag Archives: WPF

Introducing the ContentSlider control

In my very first article, I wrote an article about an implementation of a solution allowing to use transition (using a sliding effect) between views in a WPF application.

As a reminder, here when I talk about “views” I mean a screen of the application. One of this screen could be used as a login screen, the other one to setup parameters, etc.

In this article, I introduce a CustomControl that I build in order to re-use the implementation I described in an easy way. Basically, using this control, you can write something like:


    

All the specific stuff related to the transition (the animation, the use of a VisualBrush…) is handled INSIDE the control so that it is completely transparent to use.

From C# code point of view, you’ll need to use 3 functions:

  • PrepareSlide()
  • SlideToLeft()
  • SlideToRight()

The first one (PrepareSlide) must be called right before changing the content of the view. It will create a “snapshot” of the view so that it will become possible to animate it.

The next two one should be called to slide the content to the left (or to the right).

I hope you’ll enjoy it. Here is a solution containing the control with example.

Read on a forum: only problems with WPF…

A couple of days ago, I found a post on a WPF forum with the title “Only problems with WPF…”, and it basically looks like the following:

“When I installed VS.net express 2008, I was happy because I thought that with WPF I’ll be able to build nice UI. Unfortunately, I have the felling this is more like a source of problems… I spent several hours to fill a ListView with some data and the result is dirtier than with WinForms. The designer in VS.net sucks and  many controls are missing. It was so simple before…”

I wanted to give my point of view about that kind of reasoning because a couple of months ago, I think I had more or less the same… So, what makes WPF so different ? Or why I cannot just use my WinForms background and start to build wonderfull apps ?

I think that WPF is more than just a new framework or new classes. It is more than that because when you work with WPF, you have to change the way you think and design your apps.

  • You have to change the way your work with controls because you can apply new Style and Template to them so that you can completely change the way they look
  • You have to change the way you design your apps because of DataBinding and Commands
  • You have to… forget almost every things you already know, and be ready to learn again !

If I can give an advice, I would suggest to read a good WPF book. A couple of weeks ago, I finished to read WPF unleashed, by Adam Nathan [1. available at amazon.com], and I really think that having this kind of the book is the right way start working with WPF. A lot of cool website are also full of interesting resources, CodeProject is maybe the one that I like the most.

To conlude, I would like to give a quick example [2. I was inspired by CT06: Applications = Designers + Developpers at Mix08 available here].

Imagine you’d like to build an application to browse a catalog of products. For each product, you need to see the name of the product, its designer, a description and an image. You also would like to have navigation build around the use of 2 arrows to browse products:

Building a WPF application

How could you achieve this ? You might think about several ways to do it. The point is that you can do this by only using a ListBox and changing its style ! Isn’t amazing ? Go ahead and check the full video at http://sessions.visitmix.com/.

Using animated navigation pages in a WPF application

Article updated ! You can now download the example as a Visual Studio 2008 solution.
Article updated ! For a more complete solution, please take a look at this post

Introduction

Before going into fun topics, let me give some information about myself. I started to play with WPF about 1 year ago. Since the beginning, I fell in love with this new technology and the more I work with it, the more I like it. Today, I consider I’m still a newbie in the WPF world and this is my first article, so please forgive me if I do some mistakes. Please also forgive my English as this is not my natural language (I’m French).

In this article, I describe a technique that I’ve been using in order to use navigation pages in a WPF application. In the next section, I’m going to give more details about what I mean by “navigation pages”.

Requirements

Many applications are made up several screens. Here when I use the word “screen” I mean a view in the application. For example, you might have a view as a welcome screen and several other views.

In this case, you would like the current screen to display the current view, but you also need a technique to switch from one view to another. If you also want to improve the user experience, you might want to have some kind of animation when the user switches from one view to another.

A possible animation is to use a “slide effect”:

Using animation when changing current views

I’m going to describe 2 techniques that could be used to achieve this behaviour. I will also show you why the last one is better than the first one.

Continue reading Using animated navigation pages in a WPF application