Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

WPF: A Beginner's Guide - Part 6 of n

, 5 Apr 2008 CPOL
An introduction into WPF Styles and Templates.
part6_styles_and_templates.zip
Part6_Styles_And_Templates
Styles_And_Templates
Beatriz Costa Planet ListBox
bin
Debug
Styles_And_Templates.exe
Styles_And_Templates.vshost.exe
Styles_And_Templates.vshost.exe.manifest
Data
Images
2moons_2.gif
DataLogo.png
earglobe.gif
jupglobe.gif
marglobe.gif
merglobe.gif
nepglobe.gif
planetx.jpg
plutoch_2.gif
sun.jpg
uraglobe.gif
venglobe.gif
obj
Debug
Bea Costa Planet ListBox
Beatriz Costa Planet ListBox
Templates
TempPE
Properties
Settings.settings
part6_styles_and_templates_vb.zip
Part6_Styles_And_Templates_VB
Part6_Styles_And_Templates_VB
Beatriz Costa Planet ListBox
bin
Debug
Part6_Styles_And_Templates.exe
Part6_Styles_And_Templates.vshost.exe
Part6_Styles_And_Templates.vshost.exe.manifest
Data
Images
2moons_2.gif
DataLogo.png
earglobe.gif
jupglobe.gif
marglobe.gif
merglobe.gif
nepglobe.gif
planetx.jpg
plutoch_2.gif
sun.jpg
uraglobe.gif
venglobe.gif
My Project
MyExtensions
Settings.settings
obj
Debug
Beatriz Costa Planet ListBox
TempPE
Part6_Styles_And_Templates_VB.vbproj.user
<Window x:Class="Styles_And_Templates.DemoLauncherWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Styles_And_Templates"
    Title="Styles And Templates" Height="600" Width="600" 
    ResizeMode="CanResizeWithGrip"    
    WindowStartupLocation="CenterScreen">
    
    <Window.Resources>
        
        <!-- Listbox DemoListItem Type Template -->
        <DataTemplate x:Key="demoItemTemplate" DataType="x:Type local:DemoListItem">
            <StackPanel Orientation="Horizontal" Margin="10">
                <Path Name="pathSelected" Fill="White" Stretch="Fill" Stroke="White" Width="15" 
				    Height="20" Data="M0,0 L 0,15 L 7.5,7.5" 
				    Visibility="Hidden"/>
                <Border BorderBrush="White" BorderThickness="4" Margin="5">
                    <Image Source="Images/DataLogo.png" Width="45" Height="45"/>
                </Border>
                <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                    <TextBlock FontFamily="Arial Black" FontSize="20" 
                           FontWeight="Bold"
                           Width="auto" Height="auto"
                           Text="{Binding Path=DemoName}"    />
                    <TextBlock FontFamily="Arial" FontSize="10" 
                           FontWeight="Normal"
                           Width="auto" Height="auto"
                           Text="{Binding Path=WindowName}" />  
                </StackPanel>
            </StackPanel>
            <DataTemplate.Triggers>
                <DataTrigger 
                    Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                    AncestorType={x:Type ListBoxItem}, AncestorLevel=1}, Path=IsSelected}" Value="True">
                    <Setter TargetName="pathSelected" Property="Visibility" Value="Visible"  />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </Window.Resources>
    
    <DockPanel LastChildFill="True">
        <!-- Top Panel-->
        <Canvas DockPanel.Dock="Top" Background="Orange" Width="auto" Height="50">
            <TextBlock FontFamily="Arial Black" FontSize="35" 
                       FontWeight="Bold" Text="Styles And Templates"
                       Width="auto" Height="auto" Canvas.Left="10" 
                       Canvas.Top="5"/>
        </Canvas>
        <!-- Bottom Panel-->
        <ListBox x:Name="lstDemos" DockPanel.Dock="Bottom" Background="White" 
                 ItemTemplate="{StaticResource demoItemTemplate}"
                 SelectionChanged="lstDemos_SelectionChanged"/>

    </DockPanel>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sacha Barber
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
 
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
 
Both of these at Sussex University UK.
 
Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 5 Apr 2008
Article Copyright 2008 by Sacha Barber
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid