How can I access Editor properties when my Editor is created as a DataTemplate?

Editors for WPF Forum

Posted 4 years ago by JP Garza
Version: 19.1.0685
I am trying to add functionality to my editor such as: (4a - LL(*) Parser), (4c - Error Handling), etc. But, I am noticing that most sample app quickstarts are setting the editor's attributes on the the .xaml.cs file. 

If my Editors are created like this:

<DataTemplate DataType="{x:Type local:DocumentItem}">
  <syntaxeditor:SyntaxEditor x:Name="codeEditor" />
How can I (for example) access my codeEditor attributes to replicate this code you guys provide on QuickStart.GettingStarted05:
private void OnErrorListViewDoubleClick(object sender, MouseButtonEventArgs e)
    ListBox listBox = (ListBox)sender;
    IParseError error = listBox.SelectedItem as IParseError;
    if (error != null)
        editor.ActiveView.Selection.StartPosition = error.PositionRange.StartPosition;

Comments (1)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA


Due to the nature of WPF DataTemplates, the only way you can really get an instance when it's supplied via a DataTemplate is to walk down the visual tree and look for the control type.  We have a VisualTreeHelperExtended class that has helpful methods for working with the visual tree.

If you have the ability to store the related document item instance with the error item, then you could ensure the document item's tab is activated in the DockSite prior to looking for the SyntaxEditor instance in it.  You'd probably also have to call UpdateLayout after activating the tab to ensure the visual tree is fully reconstructed if a tab selection change occurs.

Actipro Software Support

The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.