SyntaxEditor and EditorSearchView

SyntaxEditor for WPF Forum

Posted 10 years ago by cowcow
Version: 10.1.0521
Avatar
HI,

I am developing a Tabbed MDI interface using the Docking Control.
The content of the DocumentWindow is a Uesrcontrol called ucEditor which contains a SyntaxEditor control. I use the following code to create the DocumentWindow dynamically

==============================
Dim editor As New ucEditor
....
' Create the document
Dim documentWindow As New DocumentWindow(dockSite, name, title, New BitmapImage(New Uri("/Resources/Images/TextDocument16.png", UriKind.Relative)), editor)

==============================

I have also put an EditorSearchView control in the MainWindow
I am using VB.NET in VS2010

My Question is:
---------------
Is it possible to bind the SyntaxEditor control in the Usercontrol to the EditorSearchView control in the MainWindow?

What I want to do is to allow the EditorSearchView control bind to the SyntaxEditor in the selected tab? So that when the user do the searching, it always search the SyntaxEditor in the selected DocumentWindow.

If it's possible, can anyone please give me a sample code how to do it?

Thanks,
Cow

[Modified at 05/11/2010 07:00 AM]

Comments (4)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

The TabbedMdiHost has a PrimaryWindow property that you can use to get the the DockingWindow whose tab is active. If you are using WPF Studio 2010.1, you can bind the PrimaryWindow property to the EditorSearchView.SyntaxEditor property. Create a new converter type which returns the syntax editor contained within your DocumentWindow, and set the binding to use this converter.

Here is an example of the binding code:

Dim binding As New Binding() 
binding.Source = tabbedMdiHost 
binding.Path = New PropertyPath(TabbedMdihost.PrimaryWindowProperty) 
binding.Converter = New DockingWindowToSyntaxEditorConverter() 
editorSearchView.SetBinding(EditorSearchView.SyntaxEditorProperty, binding)
Here is an example of the DockingWindowToSyntaxEditorConverter.Convert(...) code, where editor1 is a SyntaxEditor control:

Dim documentWindow As DocumentWindow = TryCast(value, DocumentWindow) if(documentWindow IsNot Nothing) 
    Return documentWindow.editor1 
Return Nothing
Please let us know if you have further questions.

[Modified at 05/13/2010 07:59 AM]


Actipro Software Support

Posted 10 years ago by cowcow
Avatar
Hi,

Thank you for your example.

I am not quite understand what you mean:

DockingWindowToSyntaxEditorConverter.Convert(...) code


Do you mean something similar to this:


Imports ActiproSoftware.Windows.Controls.SyntaxEditor
Imports ActiproSoftware.Windows.Controls.Docking

Public Class DockingWindowToSyntaxEditorConverter

Public Function Convert(ByVal value As Object) As SyntaxEditor

Dim documentWindow As DocumentWindow = TryCast(value, DocumentWindow)

If (documentWindow IsNot Nothing) Then
Return documentWindow ????? <---------- However, I cannot access the editor1 from documentWindow
Else
Return Nothing
End If
End Function

End Class




1. This is my DockSite Workspace part, and the EditorSearchView:


<docking:Workspace>
<docking:TabbedMdiHost x:Name="tabbedMdiHost" >
<docking:TabbedMdiContainer Name="TabbedMdiContainer1" >

</docking:TabbedMdiContainer>
</docking:TabbedMdiHost>
</docking:Workspace>


.....
<docking:ToolWindow Title="Find/Replace" ImageSource="/Resources/Images/Properties16.png">
<editor:EditorSearchView Name="EditorSearchView1" />
</docking:ToolWindow>



Remark: The DocumentWindow will be created in runtime.



2. In the Class MainWindow, I use the following function to create the DocumentWindow in runtime.


Private Function CreateTextDocumentWindow(ByVal filename As String) As DocumentWindow
{

Dim editor As New ucEditor
.....

' Create the document
Dim documentWindow As New DocumentWindow(dockSite, name, title, New BitmapImage(New Uri("/Resources/Images/TextDocument16.png", UriKind.Relative)), editor)

}


where ucEditor is a Usercontrol which contains the SyntaxEdior.


3. In the Class ucEditor, i have created the following property


Public ReadOnly Property SyntaxEditor() As SyntaxEditor
Get
Return SyntaxEditor1
End Get
End Property




4. The SyntaxEditor does not contain in the DocumentWindow directly. Instead, it contains in a Usercontrol (ucEditor) is linked to the DocumentWindow in runtime (see step 2)




In fact, I have no idea how to do the binding:

e.g: bind the DocumentWindow.ucEditor.SyntaxEditor to EditorSearchView1


I would be appreciate it if you can give me an example.


I am sorry that I am newbie to WPF, and still trying to catch up with this new technology


Thanks,
Cow
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

The DockingWindowToSyntaxEditorConverter was an example of an IValueConverter. See the MSDN documentation for more information, here:

http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx

As for accessing the SyntaxEditor instance to set up the binding, you seem to have already added a SyntaxEditor property to your ucEditor class, so in the converter, you would return the value of that property. The converter's Convert function might look something like this:

Dim documentWindow As DocumentWindow = TryCast(value, DocumentWindow)
if(documentWindow IsNot Nothing)
    Dim editor As ucEditor = TryCast(documentWindow.Content, ucEditor)
    if(editor IsNot Nothing)
        Return editor.SyntaxEditor
Return Nothing
Please let me know if you have further questions.


Actipro Software Support

Posted 10 years ago by cowcow
Avatar
After changing the PropertyPath to tabbedMdiHost.PrimaryWindowProperty, it's then work.

binding.Path = New PropertyPath(tabbedMdiHost.PrimaryWindowProperty)


Thanks
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.