Does anyone know of a working example for putting the WPF syntax editor in a winform? I've searched all over, and even chatGPT, but it can't provide a working example.
Hello Sean,
Thank you for contacting Infragistics. This is documented on MSDN
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/walkthrough-hosting-a-wpf-composite-control-in-windows-forms?view=netframeworkdesktop-4.8
After you've added the assemblies for the XamSyntaxEditor, adding the component to a Windows Forms project is fairly straightforward.
eg,
public partial class Form1 : Form { private ElementHost _ctrlHost; public XamSyntaxEditor syntaxEditor; public TextDocument document; public Form1() { InitializeComponent(); _ctrlHost = new ElementHost(); syntaxEditor = new XamSyntaxEditor(); _ctrlHost.Child = this.syntaxEditor; document = new Infragistics.Documents.TextDocument(); document.InitializeText("Hello, World!"); syntaxEditor.Document = document; _ctrlHost.Width = 800; _ctrlHost.Height = 450; this.Controls.Add(_ctrlHost); }
Let me know if you have any questions.
Thanks, that did the trick. One more thing... I'm trying to use it as a sql parser and I'm using the code on this page...
Supported Languages - Infragistics WPF Help
syntaxEditor.Document.Language = TSqlLanguage.Instance;
But it tells me...
Cannot resolve symbol 'TSqlLanguage'
I'd also like to show line numbers.
After adding these assemblies I don't see the issue you described above:
InfragisticsWPF.dll
InfragisticsWPF.Documents.TextDocument.dll
InfragisticsWPF.Documents.TextDocument.TSql.dll
InfragisticsWPF.Controls.Editors.XamSyntaxEditor.dll
That's weird cause when I add those I still get an error on this line:SyntaxEditor.Document.Language = TSqlLanguage.Instance; FormMain.cs(71, 22): [CS0012] The type 'TextDocument' is defined in an assembly that is not referenced. You must add a reference to assembly 'InfragisticsWPF.Documents.TextDocument, Version=23.1.20231.41, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb'.
Remove the Infragistics4 assemblies. They are for our Windows Forms tools. You want the WPF assembly.
Ok I changed out that dll and got rid of a couple others for Infragistics4, but I had to keep one cause I've got a combo editor on the page. It's a .net project and I'm ElementHost; for the WPF control.
Anyway, same errors.
Please attach another sample replicating the issue. The previous sample you provided contained a reference to an image that was preventing the app from running.
Dude, it totally works now. Thanks for taking the extra time on this one.
The new app runs fine without errors. Just make sure to include all the assemblies. I noticed you've been mixing WPF4 and the versionfree assemblies.
For context here is what I did, I added the WPF4 syntaxeditor dll and removed the version free ones and everything ran without errors.
Ok, I just uploaded a new version. If you run ConnParameterQB you should get the error at hand and not all the others.
I get the following warning in Visual Studio, and when I rebuild the solution I get two errors
Because the app won't recompile I get the following error prompt on run.
Done.