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.
// ***********************************************************************
// some other content here
// some other content here
// ***********************************************************************
public class TestClass
{
}
Hi, I have a problem with using SyntaxEditor.
There are two errors when using Korean.
1. When I enter Korean, the caret is shown to the left of the position to be entered. (See line 19 in the Attached File 1)
To add a description of the attached file1, it was a situation in which "가나다라마바사아자차카타파하" was entered in the order, and "하" is the last letter entered, but it can be showed that "하" is located in the middle between "사" and "자". (See line 19 and I check this character with green border in the Attached File 2)
2. When Korean is present in the line, the length of the selection area represents shorter than the input width of the input characters when selected. (See line 3, 19, 20, 21, 27, 28 in the Attached File 3)
I found that the same defect occurred in Windows11 and Windows10.
I hope it will be resolved as soon as possible.
Localize the tooltips for the match case button, the match word button and the use regular expression button.
Currently, the tooltips of the buttons are using hardcoded strings in English.
To translate the tooltips, you can get the corresponding buttons on load of the syntax editor control and replace their tooltips manually.
private void syntaxEditor_Loaded(object sender, RoutedEventArgs e)
{
var buttons = this.syntaxEditor.ChildrenOfType<RadToggleButton>();
var matchCaseButton = buttons.FirstOrDefault(x => x.Name == "PART_MatchCaseButton");
var matchWordButton = buttons.FirstOrDefault(x => x.Name == "PART_MatchWordButton");
var useRegularExpressionsButton = buttons.FirstOrDefault(x => x.Name == "PART_UseRegularExpressionsButton");
matchCaseButton.ToolTip = CreateToolTip("SyntaxEditor_MatchCase"); // these are custom localization resource keys that should be manually defined by the developer that uses this solution
matchWordButton.ToolTip = CreateToolTip("SyntaxEditor_MatchWord");
useRegularExpressionsButton.ToolTip = CreateToolTip("SyntaxEditor_UseRegularExpressions");
}
private static ToolTip CreateToolTip(string resourceKey)
{
var toolTip = new ToolTip();
toolTip.Content = LocalizationManager.Manager.GetStringOverride(resourceKey);
return toolTip;
}
Good morning,
can You implement in one of the next releases the regex and case sensitive search? I provided you the Visual Studio 2019 search screenshot
Single line folding regions is falsely recognized (by default it should be avoided) and messes up with outer regions.
For example
1 [
2 [ inner region]
3]
There should be no folding button on the inner line. Collapsing line 1 does not collapse 3 but only 1 and 2 which is wrong.