我想在我的WPF应用程序中使用一些小的ScintillaNet控件。我已经从ScintillaNet存储库编译了WPF分支。 我添加了Scrintilla控件:
<UserControl x:Class="LogicEditor.View.ScriptInput"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:scintilla="http://scintillanet.codeplex.com"
mc:Ignorable="d"
d:DesignHeight="63" d:DesignWidth="195">
<Grid>
<scintilla:ScintillaWPF HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="_scintilla" />
</Grid>
</UserControl>
控件看起来很好。如果我增加控制,则scintilla控制也会增加,但如果我减少控制,则闪烁控件会保持大小并与其他UI重叠。
我查看了ScintillaNet.WPF的示例应用程序:SCide.WPF。在这个应用程序中,一切正常,但我看不出与我的代码有任何相关的区别。
我认为调整大小和重叠是两个不同的问题。 我还尝试了没有WPF包装器的普通WindowsFormsHost,但我遇到了同样的问题。
有人可以帮忙吗?
修改 仅当Scintilla控件位于List
中时才会发生这种情况答案 0 :(得分:1)
我知道这个问题已经超级老了但是我想在这里留下一个解决方案以防其他人遇到这个问题。似乎ScintillaNET不喜欢在WPF ScrollViewer控件中托管。
我无意中让我的WindowsFormHost控件由ContentPresented呈现,而ContentPresented内部(你猜对了)是一个ScrollViewer。甚至使用带有ScrollBarVisibility的ScrollViwer禁用/隐藏垂直滚动条也不起作用。它似乎与虚拟化无关,因为必须启用它。由于Scintilla实现了自己的滚动,因此解决方案是避免将ScintillaNET托管在任何形式的ScrollViewer中,并让它本地处理其滚动内容。
你的问题是List有一个ScrollViewer。把它拿出来它应该解决它。
答案 1 :(得分:1)
我知道这个问题已经超级老了,但我遇到了同样的问题,并通过自定义面板解决了这个问题,最小化了文本编辑器所需的大小:
public class ScintillaPanel : Panel
{
protected override Size MeasureOverride(Size availableSize)
{
var children = InternalChildren.OfType<UIElement>();
var firstChild = children.FirstOrDefault();
if (firstChild != null)
firstChild.Measure(new Size(0, 0));
return new Size(0, 0);
}
protected override Size ArrangeOverride(Size finalSize)
{
var children = InternalChildren.OfType<UIElement>();
var firstChild = children.FirstOrDefault();
if (firstChild != null)
firstChild.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
return finalSize;
}
}
然后像这样包裹scintilla控件:
<local:ScintillaPanel>
<WindowsFormsHost>
<scintilla:Scintilla/>
</WindowsFormsHost>
</local:ScintillaPanel>