Click here to Skip to main content
13,000,982 members (60,121 online)
Click here to Skip to main content


110 bookmarked
Posted 28 Oct 2007

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

, 28 Oct 2007
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
Architect Infragistics
United States United States

I’m a passionate Platform Architect at Infragistics.

I’m a long-time WPF-Prism fanatic who enjoys writing developer tools and line of business applications.

My current front end passions are: XAML platforms (Xamarin.Forms, Xamarin, UWP, and WPF), Electron, ES2015 (ES6), Node.js, Aurelia, and AngularJS (Angular 1.5.x).

For the back end I use what is appropriate for the project: SQL Server and ASP.NET WebAPI, MongoDB, Express, Azure, Firebase, etc.

I am very pragmatic software engineer and strive to write simple, maintainable, and testable code. Simple code allows for solving complex problems in a maintainable way.

My Blog

My Github Repros

My YouTube Videos

Just a grain of sand on the worlds beaches.

You may also be interested in...

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