third-party libraries

Written by

in

Modern WPF applications often suffer from a common visual flaw: they rely on outdated, gray, Windows 7-era default control styles. While WPF remains an incredibly powerful framework for building enterprise desktop software, its out-of-the-box controls do not fit into today’s world of clean lines, subtle animations, and dark modes.

One of the most requested structural elements for modern desktop dashboards is the Accordion Menu—a vertically stacked list of headers that expand to reveal sub-navigation items. While WPF does not have a native “Accordion” control, you can easily build a beautiful, high-performance, modern Accordion by restyling the native TreeView or building a custom item control stack.

This guide will show you how to design and style a modern, production-ready WPF Accordion Menu using clean XAML, custom control templates, and smooth visual states. The Structural Blueprint

To build an accordion that behaves correctly, we need a parent container that holds multiple expandable sections. Only one section should ideally expand at a time, though a true accordion should support flexible configuration.

Instead of dragging in heavy, third-party libraries, we can leverage the built-in Expander control nested inside a styled ItemsControl (or a ListBox if you require strict selection tracking).

Here is the foundational data model for our menu navigation:

public class AccordionItem { public string HeaderTitle { get; set; } public string IconData { get; set; } // Path geometry for modern vector icons public List SubItems { get; set; } } Use code with caution. Designing the Modern Theme Dictionary

Modern UI design relies heavily on flat design principles, generous padding, high-contrast typography, and explicit control over interactive visual states (Hover, Pressed, Selected, and Disabled).

Create a ResourceDictionary named ModernAccordionStyle.xaml. We will first define our palette variables to keep the code clean and maintainable.

#1E1E24 #2A2A32 #6C5CE7 #FFFFFF #A0A0AA Use code with caution. Rewriting the Expander Template

The secret to a beautiful Accordion lies entirely in flattening the Expander control. The native WPF expander uses a round toggle button with a rigid layout. We need to replace it with a wide, sleek header bar that changes color smoothly when hovered.

Add the following style to your dictionary to override the default Expander template:

Use code with caution. Styling the Inner Sub-Navigation Links

When the accordion opens, the secondary items must look like flat, clean navigation links rather than standard desktop buttons. We can achieve this by customizing a standard Button style to remove border footprints, align text left, and give it a slight accent pop when active.

Use code with caution. Implementing the Final Layout

With the styles successfully created, implementing the Accordion into your Sidebar markup becomes remarkably straightforward. Wrap your implementation in an overall background panel to give it depth.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *