NullReferenceException thrown on opening the CompletionListWindow when RadSyntaxEditor is hosted in a non-WPF application (usually WinForms) and there are no WPF Application and MainWindow initialized.
This can happen if the RadSyntaxEditor for WPF is hosted in a WinForms application. In this scenario the System.Windows.Application.Current and its MainWindow are not initialized, which is what the IntelliPrompt positioning logic relies on.
Exception details:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
> Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPosition(System.Windows.Point pointInScreen) Line 452 C# Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPosition(System.Windows.Point pointInEditorPresenter, System.Windows.Point pointAboveTheCaret) Line 442 C# Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPositionInView() Line 480 C# Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.InitializeIntellisense() Line 401 C# Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.Show(Telerik.Windows.Controls.SyntaxEditor.UI.CaretPosition caretStartPosition, Telerik.Windows.Controls.SyntaxEditor.UI.CaretPosition caretEndPositions) Line 211 C#
Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.Show() Line 182 C#
To work this around, you can initialize a new WPF application and MainWindow and create a hidden HwndSource for the MainWindow. This should happen before showing the WPF content in the WinForms application's code.
public Form1()
{
InitializeComponent();
new System.Windows.Application();
System.Windows.Application.Current.MainWindow = new System.Windows.Window();
var parameters = new HwndSourceParameters("HiddenHost")
{
Width = 1, Height = 1,
WindowStyle = unchecked((int)0x80000000) // WS_POPUP | WS_EX_NOACTIVATE
};
var hwndSource = new HwndSource(parameters);
hwndSource.RootVisual = System.Windows.Application.Current.MainWindow;
// other code here
ElementHost host = new ElementHost { Dock = DockStyle.Fill };
host.Child = wpfControl
this.Controls.Add(host);
}
I do have some feedback on this component. I love it, but of course there are some areas where improvement can be made. For instance, in the screenshot below, I have highlighted some words where improvement can be made.
When using XML Tagger, XML Folding tagger with XML text document, the folding tagger freezes the UI while typing.
Generally in Visual Studio, the XML Folding tagger is processed in background while in SyntaxEditor this is done on the UI thread.
Several optimization options might be applied:
- process xml folding in background
- process folding similar to process search while typing - a period of inactivity time is needed to invalidate the search / folding
- caching - if the edit does not change the folding configuration, no processing and redrawing of folding is required
- some parts for extracting tooltip content and folded content should be optimized
We want to have the option to replace texts only in a selected part of the document.
Use Notepad++ as a reference to check this feature.
Hello,
We would like to use SyntaxEditor by providing our own programming language definition. It would be great to have the ability to feed SyntaxEditor with a language definition file. This file could be use an EBNF-like format to provide syntax coloration.
Thanks & regards,