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.
I did add the tsql assembly. I started my last post with that. I don't know if the winforms doc lib was put there my me or by something else.
Please modify my sample or attach a new sample project reproducing the behavior.
Ok, I tried uploading my project but it was too big I guess. It uploaded just fine, and I hit reply and then it just never showed up. Perhaps if it were too big you guys could put an error on the page.
Anyway, I took out all your dlls and it's much smaller now.
ConnParameterQB.zip
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'.
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.