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

Editors for WPF Forum

The latest build of this product (v2019.1 build 0685) was released 4 months ago, which was before this thread was created.
Posted 13 days ago by JP Garza
Version: 19.1.0685
Avatar
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" />
</DataTemplate>
 
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;
        editor.Focus();
    }
}
 

Comments (1)

Posted 13 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

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

Add Comment

Please log in to a validated account to post comments.