2

我正在尝试在我正在构建的 WPF 应用程序中使用来自 SharpDevelop 4.0 项目的 ICSharpCode.AvalonEdit.TextEditor 控件,但我似乎无法让它工作。

我从 svn://svnmirror.sharpdevelop.net/sharpdevelop/trunk/SharpDevelop/src/Libraries/AvalonEdit 在修订版 4304 中检查了源代码的副本。然后,我使用 Visual Studio 2008 SP1 构建了该项目,该项目没有成功错误。

然后我创建了一个空白的新 WPF 项目,将构建 DLL 添加到工具箱中,并将 TextEditor 控件拖放到默认的空窗口中,如下所示:

<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>

但是,当我运行项目时,表单完全空白。没有插入符号,鼠标光标保持默认指针,窗口不响应按键。

我错过了什么,还是 AvalonEdit 有点坏了?

[编辑:我开始认为这可能与我的特定设置有关。我正在运行 64 位 Windows 7 RC。这可能与它有关吗?我试过只为 x86 构建它,没有区别。]

4

3 回答 3

2

你确定你的命名空间声明是正确的吗?

你可以尝试这样的事情:

<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>

我能够让它毫无问题地工作。

于 2009-07-12T14:06:32.637 回答
0

这适用于我的最新版本

<DockPanel LastChildFill="True">
    <avalonedit:TextEditor 
        HorizontalAlignment="Stretch"
        Name="textEditor1" 
        VerticalAlignment="Stretch" />
</DockPanel>
于 2009-07-30T17:08:10.420 回答
0

AvalonEdit TextEditor 只是一个 TextDocument 模型的视图。问题是一个新的 AvalonEdit 实例没有开始连接到任何模型实例,所以没有任何东西可以编辑。

来自 statictype 的代码起作用的原因是他没有使用<avalonedit:TextEditor/>,但是<avalonedit:TextEditor></avalonedit:TextEditor>. 这将为 Text 属性分配一个空字符串,从而导致编辑器隐式创建一个新文档。

但这与最近的 AvalonEdit 版本不再相关,编辑器现在总是会创建一个新的 TextDocument。

于 2009-07-20T23:52:49.807 回答