WPF Debugging AvalonEdit binding to Document property.

Posted by kubal5003 on Stack Overflow See other posts from Stack Overflow or by kubal5003
Published on 2010-06-07T00:37:18Z Indexed on 2010/06/07 0:42 UTC
Read the original article Hit count: 992

Filed under:
|
|

Hello,

all day long I am sitting and trying to find out why binding to AvalonEdits Document property isn't working. AvalonEdit is an advanced WPF text editor - part of the SharpDevelop project.(it's going to be used in SharpDevelop v4 Mirador).

So when I set up a simple project - one TextEditor (that's the AvalonEdits real name in the library) and made a simple class that has one property - Document and it returns a dummy object with some static text the binding is working perfectly.

However in real life solution I'm binding a collection of SomeEditor objects to TabControl. TabControl has DataTemplate for SomeEditor and there's the TextEditor object.

<TabControl Grid.Column="1" x:Name="tabControlFiles" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
    <TabControl.Resources>
        <DataTemplate DataType="{x:Type m:SomeEditor}">
            <a:TextEditor 
            Document="{Binding Path=Document, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource NoopConverter}, IsAsync=True}" 
            x:Name="avalonEdit"></a:TextEditor> 
        </DataTemplate>     
    </TabControl.Resources>

    <TabControl.ItemContainerStyle>
        <Style BasedOn="{StaticResource TabItemStyle}" TargetType="{x:Type TabItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected}"></Setter>
        </Style>
    </TabControl.ItemContainerStyle>
</TabControl>

This doesn't work. What I've investigated so far:

  • DataContext of TextEditor is set to the proper instance of SomeEditor
  • TextEditors Document property is set to some other instance than SomeEditor.Document property
  • when I set breakpoint to no-op converter that is attached to that binding it shows me the correct value for Document (the converter is used!)
  • I also dug through the VisualTree to obtain reference to TextEditor and called GetBindingExpression(TextEditor.DocumentProperty) and this did return nothing

  • WPF produces the following information:

    System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Document; DataItem='SomeEditor' (HashCode=26280264); target element is 'TextEditor' (Name='avalonEdit'); target property is 'Document' (type 'TextDocument')

  • SomeEditor instance that is bound to already has a created and cached copy of Document before the binding occurs. The getter is never called.

Anyone can tell me what might be wrong? Why BindingExpression isn't set ? Why property getter is never called?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding