WPF SyntaxEditor in ElementHost fails to change scrollbar theme

SyntaxEditor for WPF Forum

Posted 1 year ago by (Anonymous)
Version: 18.1.0673
Platform: .NET 4.7
Environment: Windows 10 (64-bit)
Avatar

If you create a WPF app and add a WPF SyntaxEditor control, it sets the colours as per the current theme as expected.

However, if you create a WinForms app and add a WPF SyntaxEditor as the child of the ElementHost control, all theme aspects are correct appart from the scrollbars.

  1. Create a WinForms application called 'WindowsFormsApp1' and references for ActiproSoftware.Shared / SyntaxEditor / Text WPF dlls.
  2. Add the file from the Actipro Samples 'Dark.vssettings' as an embedded resource
  3. Copy the following code into 'WindowsFormsApp1.cs'
  4. Run the application, and you should see the MetroDark theme is used for everything except the scrollbars?
using ActiproSoftware.Windows.Controls.SyntaxEditor;
using ActiproSoftware.Windows.Controls.SyntaxEditor.Highlighting;
using ActiproSoftware.Windows.Controls.SyntaxEditor.IntelliPrompt.Implementation;
using ActiproSoftware.Windows.Themes;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private ElementHost elementHost;
        private SyntaxEditor syntaxEditor;

        public Form1()
        {
            InitializeComponent();

            elementHost = new ElementHost();
            this.Controls.Add(elementHost);
            elementHost.Dock = DockStyle.Fill;
            syntaxEditor = new SyntaxEditor();
            elementHost.Child = syntaxEditor;
        }

        protected override void OnLoad(EventArgs e)
        {
            ThemeManager.BeginUpdate();
            try
            {
                ThemeManager.AreNativeThemesEnabled = true;
                ThemeManager.CurrentTheme = ThemeName.MetroDark.ToString();
            }
            finally
            {
                ThemeManager.EndUpdate();
            }

            var classificationTypes = AmbientHighlightingStyleRegistry.Instance.ClassificationTypes.ToArray();
            foreach (var classificationType in classificationTypes)
                AmbientHighlightingStyleRegistry.Instance.Unregister(classificationType);

            new DisplayItemClassificationTypeProvider().RegisterAll();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApp1.Dark.vssettings"))
            {
                AmbientHighlightingStyleRegistry.Instance.ImportHighlightingStyles(stream);
            }

            CommonImageSourceProvider.DefaultImageSet = CommonImageSet.MetroDark;

            base.OnLoad(e);
        }
    }
}

[Modified 1 year ago]

Comments (2)

Answer - Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I believe the themes will not work correctly if a WPF Application hasn't been properly initialized in Application.Current.  WPF apps do this by default.  But in a WinForms app, if you simply create a new WPF Application() object at app startup before UI is referenced, it should inject one into Application.Current.


Actipro Software Support

Posted 1 year ago by (Anonymous)
Avatar

Thanks it works now!

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.