views:

1161

answers:

3

I'm trying to use the ICSharpCode.AvalonEdit.TextEditor control from the SharpDevelop 4.0 project in a WPF app that I'm building, but I can't seem to get it to work.

I checked out a copy of the source code from svn://svnmirror.sharpdevelop.net/sharpdevelop/trunk/SharpDevelop/src/Libraries/AvalonEdit at revision 4304. Then, I built the project using Visual Studio 2008 SP1, which succeeded without errors.

I then created a blank new WPF project, added the build DLL to the toolbox and dropped the TextEditor control onto the default empty window, like so:

<Window x:Class="AvalonEditTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"        
    Title="Window1" Height="300" Width="300" >
    <Grid x:Name="LayoutRoot">
        <avalonedit:TextEditor Name="textEditor" />
    </Grid>
</Window>

However, when I run the project, the form comes up completely blank. No caret, the mouse cursor stays the default pointer, and the window does not respond to keypresses.

Am I missing something, or is AvalonEdit just a little broken?

[EDIT: I'm starting to think it might be related to my specific setup. I'm running the 64-bit Windows 7 RC. Might that have something to do with it? I've tried building it for x86 only, made no difference.]

+2  A: 

Are you sure your namespace declaration is correct?

You can try something like this:

<Window x:Class="Editor.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" 
    xmlns:e="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit">
    <Grid>
        <e:TextEditor x:Name="Editor" WordWrap="True" Height="200">          
        </e:TextEditor>
    </Grid>
</Window>

I was able to get it to work without any issues.

HS
Just tried that, makes no difference on my machine. What revision of the source code/binaries are you using?
Jacob
Also using 4304. I just checked out the AvalonEdit part. I had to modify the project file to make it build. Then I added a reference to that dll in my project and then used the xaml given above.I didn't add the control to the toolbox.
HS
oh, and, I'm running on 32-bit Vista. Since you didn't get any compile errors, it could very well be an architecture issue.
HS
A: 

The AvalonEdit TextEditor is just a view for a TextDocument model. The problem was that a new AvalonEdit instance didn't start connected to any model instance, so there wasn't anything to edit.

The reason the code from statictype worked was that he didn't use <avalonedit:TextEditor/>, but <avalonedit:TextEditor></avalonedit:TextEditor>. This will assign an empty string to the Text property, which caused the editor to implicitly create a new document.

But this isn't relevant with recent AvalonEdit versions anymore, the editor will now always create a new TextDocument.

Daniel
Exactly how recent is recent?
Jacob
Actually it was longer ago than I thought - revision 3930.Since you're using 4304, it must be a different problem in your case.Then I'd guess that the text editor doesn't find its template. No idea why that would happen, though.
Daniel
A: 

This works for me with the latest build

<DockPanel LastChildFill="True">
    <avalonedit:TextEditor 
        HorizontalAlignment="Stretch"
        Name="textEditor1" 
        VerticalAlignment="Stretch" />
</DockPanel>
Andre