Why WPF Rocks (Custom Layout Panel Showcase)

Another enhancement in WPF that makes it stand out above the rest is the excellent layout system. In WinForms, a button has a Top and Left property. Now you can move the button around on the form. What if you want to dock the button to the top? Lets add a property Dock! This works... but what if I want to randomly scatter the buttons over the screen? Or if I want to automatically scale the buttons in equal sizes, even if I maximize my window? You can't keep adding properties to accommodate the layout! WPF has taken a new approach, every control in WPF has no concept of layout... Check a button in WPF, it has no Left or Top property! Well, this is crazy, how do you lay it out then? Easy, WPF introduced Layout Panels... The layout panel controls how its children is layed out on the screen.

WPF ships with loads off layout panels (StackPanel, WrapPanel, Grid, DockPanel, Canvas, etc). The layout system also use a new concept called attached properties to then position the element in the panel...

Lets look at a example that closely resemble WinForms... We add a Canvas and add a button to this canvas.

<Canvas>
    <Button />
</Canvas>

To now position the Button at Left=100 and Top=100, we use attached properties

<Button Canvas.Top="100" Canvas.Left="100"/>

This is very flexible... Now you can extend the layout system!!!

To create layout panels, have been covered extensively on the net, I will just quickly show the basics

public class MyCoolPanel : Panel
{
    protected override Size MeasureOverride(Size availableSize)
    {
        // Size...
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        // Position
    }
}

[Tip] Use the Nerd + Art snippets here...

Derive from Panel and override MeasureOverride and ArrangeOverride! Now you have great control over how big the items can/should be and where thy will be positioned!!!

Here is a collection of the best custom layout panels I found on the internet:

PS. All of these panels source is also available!

FishEyePanel

Created by Paul Tallett

AnimatingStackPanel

Released as part of Mike Mars and Joe Stegman's talk at Mix '08 (Including the absolutely brilliant AnimatingPanelBase created by Robby Ingebretsen)

[NOTE] This panel has animation so I will not post a screen cap of this... run the attached application to see this panel in action!

FanPanel

Also by Paul Tallett

The FanPanel, as the name suggests, fans the items out into their position... all the items are fanned out into a wrap panel!

[NOTE] This panel has animation so I will not post a screen cap of this... run the attached application to see this panel in action!

LayeredStackPanel

Created by Nick Thuesen

RadialPanel

Created by Henry Hahn

[UPDATE] also check out this excellent article by Jobi about radial panels!!!

Panel3D

Created by Josh Smith

DiagonalPanel

Created by

 

TimelinePanel

Originally created by Rob Zelt (Part 1 & Part 2). Later released as part of blendables layout mix

PS. The blog only had a partial implementation and no source code so I implemented the rest...

ElementFlow

Created by Pavan Podila and released as part of the FluidKit

AnimatingCOSPanel

Created by Rudi Grobler

 

ColumnedPanel

Created by Sacha Barber

SpanningStackPanel

Created by Nick Thuesen

AnimatedWrapPanel

Created by Paranoid Ferret Productions

[NOTE] This panel has animation so I will not post a screen cap of this... run the attached application to see this panel in action!

AnimatingRadomCanvas

Created by Rudi Grobler (Based on AnimatingPanelBase)

[NOTE] This panel has animation so I will not post a screen cap of this... run the attached application to see this panel in action!

Here is the showcase application (including source)

[UPDATE] the link is now fixed Embarrassed

If you found the article useful, please kick it on DotNetKicks.com

Published Tuesday, April 15, 2008 7:56 AM by rudi

Comments

# Why WPF Rocks (Custom Layout Panel showcase)

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Tuesday, April 15, 2008 7:59 AM by DotNetKicks.com

# re: Why WPF Rocks (Custom Layout Panel Showcase)

Hey rudi,

I tried to acess the download for the source but the link is down.  I would love to see the source, this looks like an excellent project.

Cheers

jay

Tuesday, April 15, 2008 8:16 AM by Jay Solomon

# re: Why WPF Rocks (Custom Layout Panel Showcase)

Hi,

Download link is broken

Cornel

Tuesday, April 15, 2008 8:31 AM by Cornel

# re: Why WPF Rocks (Custom Layout Panel Showcase)

Nice one Rudi

Tuesday, April 15, 2008 8:43 AM by sacha

# sachabarber.net &raquo; Custom WPF Panels

Pingback from  sachabarber.net  &raquo; Custom WPF Panels

Tuesday, April 15, 2008 8:48 AM by sachabarber.net » Custom WPF Panels

# re: Why WPF Rocks (Custom Layout Panel Showcase)

Rudi,

I was looking at some functionality to do some layout animation, and this shows exactly what I am gonna need. Excellent stuff.

Adriaan

Tuesday, April 15, 2008 1:18 PM by Adriaan

# re: Why WPF Rocks (Custom Layout Panel Showcase)

I am so sorry about the link! It is fixed now!

Tuesday, April 15, 2008 3:05 PM by rudi

# List of Custom Layout Panel in WPF &laquo; Rams On It - .NET

Pingback from  List of Custom Layout Panel in WPF &laquo; Rams On It - .NET

Tuesday, April 15, 2008 6:41 PM by List of Custom Layout Panel in WPF « Rams On It - .NET

# Dew Drop - April 16, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - April 16, 2008 | Alvin Ashcraft's Morning Dew

Wednesday, April 16, 2008 2:56 PM by Dew Drop - April 16, 2008 | Alvin Ashcraft's Morning Dew

# WPF/Silverlight/XAML Web Links - 2004/04/18

&#160; WPF Apps Jaime Rodriguez&#39;s list of WPF in Line-of-Business case studies CodePlex Project:

Saturday, April 19, 2008 4:35 AM by Rob Relyea - Xamlified

# WPF/Silverlight/XAML Web Links - 2008/04/18

WPF Apps Jaime Rodriguez&#39;s list of WPF in Line-of-Business case studies CodePlex Project: Slick Code

Saturday, April 19, 2008 5:01 AM by Rob Relyea - Xamlified

# WPF/Silverlight为什么要使用Canvas.SetLeft()这样的方法?

这一篇Post首先从WPF的布局系统说起,介绍了布局系统中是如何应用AttachedProperty的,然后总结的阐述了为什么会出现Canvas.SetLeft()这样的语法。

Wednesday, April 23, 2008 5:05 AM by Yannic Yang

# wpf/silverlight文章推荐

还是wpf文件推荐:)

Tuesday, July 01, 2008 4:57 PM by Clingingboy

# Today&#8217;s Sites/Blogs &laquo; Roman&#8217;s Blog

Pingback from  Today&#8217;s Sites/Blogs &laquo; Roman&#8217;s Blog

Saturday, July 12, 2008 10:03 AM by Today’s Sites/Blogs « Roman’s Blog