Click here to Skip to main content
11,923,046 members (62,490 online)
Click here to Skip to main content


109 bookmarked

A WPF Problem Solved Two Very Different Ways - Using XAML Only - Using a Custom Control

, 28 Oct 2007 CPOL
Article on solving a problem using a XAML only approach and then solving that same problem using WPF custom controls.
                <Section LineHeight="2" Foreground="Black" Padding="5">
                        <LinearGradientBrush EndPoint="0.508,0.835" StartPoint="0.508,0.167">
                            <GradientStop Color="#FFFFE8D0" Offset="0"/>
                            <GradientStop Color="#FFF88206" Offset="1"/>
                    <Paragraph FontSize="14">No Code, Just XAML!</Paragraph>
                    <Paragraph FontSize="20">Get Your High Octane ListBox</Paragraph>
                <Paragraph>Within this project there are two distinct versions of the High Octane ListBox.  First there are 6 demos of ListBox &amp; ListBoxItem styles that achive all the goals, including my favorite, the CheckListBox supporting all the ListBox SelectionModes. (I was never able to get CheckBoxes stuffed into a ListBox to honor the SelectionModes.)  Next, I've included two Custom Controls that implment this same feature set but in a much different way.</Paragraph>
                <Paragraph FontWeight="Bold">XAML Only Requirements</Paragraph>
                        <Paragraph>Allow the ListBoxItems to be added in XAML</Paragraph>
                        <Paragraph>Allow the ListBox to be data bound in XAML</Paragraph>
                        <Paragraph>Allow the ListBox to be data bound in code</Paragraph>
                        <Paragraph>Allow the indicator size to be set in XAML</Paragraph>
                        <Paragraph>Allow the indicator brush to be set in XAML</Paragraph>
                        <Paragraph>Provide a UI where the indicator or CheckBox are visually separated from the corresponding ListBoxItem.</Paragraph>
                        <Paragraph>Check out demo, CheckListBox W/Selector Color for a real vivid picture of this.</Paragraph>
                        <Paragraph>ListBoxes must support Single, Multiple &amp; Extended SelectionMode</Paragraph>
                <Paragraph FontWeight="Bold">Custom Control Additional Requirements</Paragraph>
                        <Paragraph>Support the control being declared and instaintated in code without any XAML mark up</Paragraph>
                        <Paragraph>Support the changing out of the child ListBox control at run time</Paragraph>
                <Paragraph FontWeight="Bold">Comments</Paragraph>
                <Paragraph>This journey all started out when I read Josh Smith's recent Code Project article,<Hyperlink x:Name="hlToJSArticle">The WPF Thought Process</Hyperlink>.  I really wanted to take the concept of what he designed and create a XAML only version.  After getting the first one ready, it hit me to take the next step and build a WPF CheckListBox.  I also made a Custom Control version for the Charlotte Developers GUILD Fall 2007 Code Camp.</Paragraph>
                <Paragraph FontWeight="Bold">Easter Egg</Paragraph>
                <Paragraph>Be on the look out for an Easter Egg.  With Halloween just around the corner, what loose cannon could resist.  When you think you've found it, keep going.  Yes, you can find it in the XAML code, but what fun would that be?</Paragraph>
                <Paragraph>Hope someone can learn from this code,</Paragraph>
                    <Hyperlink x:Name="hlViewKSBlog" >View Karl's Blog</Hyperlink></Paragraph>
                <Paragraph Foreground="#FFc0943f">Just a grain of sand on the worlds beaches.</Paragraph>

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.


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


About the Author

Karl Shifflett
Technical Lead Logical Advantage
United States United States
Christian, Husband, Dad, Biker, Marine Corps Veteran, stage IV cancer survivor .NET, WPF & Prism fanatic, embracing Ionic, TypeScript, AngularJS, Raspberry PI, and Iot


  • December 2008 VB.NET Code Project Article Award
  • 2009 Code Project MVP
  • 2008 Code Project MVP
  • 2008 Microsoft MVP - Client App Dev
  • December 2007 VB.NET Code Project Article Award
  • Gold Medal Winner at IBM's 1998 PROIV Programming Contest in Las Vegas
Click here to check out my Blog

Just a grain of sand on the worlds beaches.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151125.3 | Last Updated 28 Oct 2007
Article Copyright 2007 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid