简体   繁体   中英

How do I get XP themed TreeView expand/collapse icons?

I have a basic C# WPF TreeView, but I do not like that the expand/collapse icons are the triangle and I want to use the plus/minus icons instead.

From this question , I noticed that you can set the Windows Theme for the application, and it uses uxtheme.dll to change to the Vista/7 theme, what is the theme DLL for changing to the XP theme and how do you add the reference line in the xaml file that is using the modified TreeView control?

UxTheme.dll provides theme services to applications using the Common Control libraries in addition to parts of Windows chrome (such as window borders and titlebars) and custom elements such as the start menu and taskbar. UxTheme.dll was introduced in 2001 with Windows XP, however the services it provides vary between Windows versions.

WPF does not use UxTheme.dll for its themeing - all WPF "visual styles" are actually vector-graphics reimplementations of the XP "Luna" (XP's Fischer-Price theme), XP "Royale" (MCE2005), and Vista/7 Aero styles. Furthermore WPF does not use the Common Controls library either, it has 100%-managed reimplementations of all the main Windows controls - this is why WPF apps tend to fall into Uncanny Valley on Windows - they look like native applications, but something isn't right about them.

I'm not a WPF expert myself, but I understand you can override rendering of particular elements, I don't know if you can do this without subclassing them, however.

I apologise for not answering your question directly, I just hope I could provide some useful insight.

Unfortunately, I believe this requires overriding the TreeView's default styles and control templates. Here is a link to MSDN: http://msdn.microsoft.com/en-us/library/ms752048.aspx . If you search for Path x:Name="Collapsed" and Path x:Name="Expanded" this is how the arrow is drawn.

You can override this by swapping the Path element with an Image for each state. Or, you could also use a Path element to draw something similar to the + - effect you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM