Visual Studio 2012 uses custom WPF controls. You can check it yourself Snoop . The Visual Studio 2012 WPF visual tree contains controls such as Microsoft.VisualStudio.PlatformUI.VsButton, Microsoft.VisualStudio.PlatformUI.Shell.Controls.TabGroupControl, Microsoft.VisualStudio.PlatformUI.SearchControl . Unfortunately, these controls are not documented and are difficult or impossible to reuse. You can only view styles of complex elements and implement them in your code.
I am creating a similar management base for the Winfried LΓΆtzsch Collection (now it is included in the MahApps.Metro Toolkit ). I also saw another collection of attractive elements. This may be helpful.
To implement support for Visual Studio themes, I use resources from Microsoft.VisualStudio.Shell.VsBrushes/VsColors and my own colors. To convert the icons to the current theme, I use the following code:
private readonly IVsUIShell5 _vsUIShell5; private string _currentThemeId; // cache icons for specific themes: <<ThemeId, IconForLightTheme>, IconForThemeId> private readonly Dictionary<Tuple<string, BitmapImage>, BitmapImage> _cacheThemeIcons = new Dictionary<Tuple<string, BitmapImage>, BitmapImage>(); protected override BitmapImage GetIconCurrentTheme(BitmapImage iconLight) { Debug.Assert(iconLight != null); return _currentThemeId.ToThemesEnum() == Themes.Light ? iconLight : GetCachedIcon(iconLight); } private BitmapImage GetCachedIcon(BitmapImage iconLight) { BitmapImage cachedIcon; var key = Tuple.Create(_currentThemeId, iconLight); if (_cacheThemeIcons.TryGetValue(key, out cachedIcon)) { return cachedIcon; } var backgroundColor = FindResource<Color>(VsColors.ToolWindowBackgroundKey); cachedIcon = CreateInvertedIcon(iconLight, backgroundColor); _cacheThemeIcons.Add(key, cachedIcon); return cachedIcon; } private BitmapImage CreateInvertedIcon(BitmapImage inputIcon, Color backgroundColor) { using (var bitmap = inputIcon.ToBitmapByPngEncoder()) { var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); var bitmapData = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat); var sourcePointer = bitmapData.Scan0; var length = Math.Abs(bitmapData.Stride) * bitmap.Height; var outputBytes = new byte[length]; Marshal.Copy(sourcePointer, outputBytes, 0, length); _vsUIShell5.ThemeDIBits((UInt32)outputBytes.Length, outputBytes, (UInt32)bitmap.Width, (UInt32)bitmap.Height, true, backgroundColor.ToUInt()); Marshal.Copy(outputBytes, 0, sourcePointer, length); bitmap.UnlockBits(bitmapData); return bitmap.ToPngBitmapImage(); } }
To invert correctly, the Light theme icon must be a different Visual Studio icon (with a gray border around, for example,
)