Document Binding, Null Reference Exception

SyntaxEditor for Silverlight Forum

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

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"
                                 Grid.Column="1" 
                                 WordWrapMode="Word" 
                                 AreWordWrapGlyphsVisible="True" 
                                 IsLineNumberMarginVisible="True" 
                                 IsCurrentLineHighlightingEnabled="True" 
                                 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 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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 10 years ago by Nathaniel Armer
Avatar

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.

https://www.dropbox.com/s/lp44aqt9p2rvgy3/SyntaxEditorDatabindingTest.zip

This is my XAML:

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:editor="http://schemas.actiprosoftware.com/winfx/xaml/syntaxeditor"
  x:Class="SyntaxEditorDatabindingTest.MainPage"
  mc:Ignorable="d"
  d:DesignHeight="300"
  d:DesignWidth="400">

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

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;
            InitializeComponent();
        }
    }
}

Thanks

[Modified 10 years ago]

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

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 (v18.1 build 0233) was released 4 years ago, which was after the last post in this thread.