I have just completed 10 day attack on Windows Presentation Foundation and after repeated false starts I have concluded I need to buy a book. In the age of Google search this may seem absurd to the average developer, however, after 8 days of trying to recreate a Windows Forms App (the other 2 days were actually useful) I am realizing I need to have a paradigm shift in my current mindset. Let us take the humble ListBox for example, the XAML would look something like this:

image        <ListBox>
            <ListBoxItem>Item 1</ListBoxItem>
            <ListBoxItem>Item 2</ListBoxItem>
            <ListBoxItem>Item 3</ListBoxItem>
            <ListBoxItem>Item 4</ListBoxItem>
        </ListBox>


So I thought that was it I *know* List Boxes in WPF … WRONG! This is not even scratching the surface my friends! Our capable WPF designers have broken the ListBox into its simplest forms. For example let us trying creating a list of Rectangles

image        <ListBox>
            <Rectangle Width="20" Height="20" Stroke="Yellow"  StrokeThickness="4" ></Rectangle>
            <Rectangle Width="20" Height="20" Stroke="Blue"  StrokeThickness="4" ></Rectangle>
            <Rectangle Width="20" Height="20" Stroke="Green"  StrokeThickness="4" ></Rectangle>
        </ListBox>

 

or ellipses…

image

        <ListBox>
            <Ellipse Width="20" Height="20" Stroke="Yellow"  StrokeThickness="4" ></Ellipse>
            <Ellipse Width="20" Height="20" Stroke="Blue"  StrokeThickness="4" ></Ellipse>
            <Ellipse Width="20" Height="20" Stroke="Green"  StrokeThickness="4" ></Ellipse>
        </ListBox>

 

…or any combination of the above. It is a type agnostic list of items you want to show. I can also orient the flow of list boxes as I see fit…

image

        <ListBox VerticalAlignment="Top">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <Ellipse Width="20" Height="20" Stroke="Yellow"  StrokeThickness="4" ></Ellipse>
            <Ellipse Width="20" Height="20" Stroke="Blue"  StrokeThickness="4" ></Ellipse>
            <Ellipse Width="20" Height="20" Stroke="Green"  StrokeThickness="4" ></Ellipse>
        </ListBox>


Can you see why I need a book, at a casual glance I thought I really knew what was going on with a simple drag and drop, but on closer inspection it is clear that I am missing some underlying goodness through my own poor ignorance.

WPF rocks!!!

Technorati Tags: ,