Document Binding, Null Reference Exception

SyntaxEditor for Silverlight Forum

Posted 8 years ago by Nathaniel Armer
Version: 14.1.0172
Platform: Silverlight 5

I was hoping to be able to bind my SyntaxEditor to a EditorDocument defined in a View Model - e.g.

<editor:SyntaxEditor x:Name="Editor"
                                 Document="{Binding Doc}" >

However in both design and run time I get a null referance exception.  I looked through the docs and samples and couldn't find any binding of this type... is this unsupported?

Comments (3)

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

Hi Nathaniel,

I tried a quick test and it worked ok for me.  It should be supported since the Document property is a dependency property.  That being said, be sure you set it to a non-null value since there could be places elsewhere that expect the Document is filled in.  I would ensure that your data context is set up prior to InitializeComponent() being called and see if that helps.

Actipro Software Support

Posted 8 years ago by Nathaniel Armer

Hi Actipro,


Thanks again for your quick response.  I'm glad to know that it should work.  That said, it's still causing me issues.  Here's a small reproducible case.

This is my XAML:

<UserControl xmlns:sdk=""

   <StackPanel Orientation="Vertical" Background="White"> 
       <sdk:Label Content ="{Binding Doc.FileName}"/> 
       <editor:SyntaxEditor Document="{Binding Doc}" /> 

And here is my code:

namespace SyntaxEditorDatabindingTest
    public partial class MainPage : UserControl
        public EditorDocument Doc { get; set; }
        public MainPage()
            Doc = new EditorDocument { FileName = "Test" };
            Doc.SetText("Hello world!");
            this.DataContext = this;


[Modified 8 years ago]

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

Hi Nathaniel,

Thank you for the sample, we were able to repro it with that.  It seems like Silverlight is pushing through a null value for SyntaxEditor.Document initially when there is a binding set and that's what is causing the problem.  Then later it pushes through the bound value.

We've made code changes for the next version that will allow this scenario to work properly.  Until then you will have to set the document programmatically instead.

Actipro Software Support

The latest build of this product (v2018.1 build 0233) was released 3 years ago, which was after the last post in this thread.