[英]Wpf- How does the textbox in visual studio collapse regions and how can I implement this in my text editor?
I need someone to point me in the right direction. 我需要有人指出我正确的方向。
What would I need to do to collapse a region of text in a textbox? 我需要做什么来折叠文本框中的文本区域?
I do not need to know how to allow a user to define regions, just how to collapse a region once you have the index and length of that region. 我不需要知道如何允许用户定义区域,只需知道在拥有该区域的索引和长度后如何折叠区域。 I also want to, like visual studio does, leave a visual reminder of collapsed regions that you can click to expand them.
我也想像视觉工作室一样,留下可以点击以展开它们的折叠区域的视觉提醒。
Visual Studio uses its own text editor control, not WPF's built in TextBox. Visual Studio使用自己的文本编辑器控件,而不是内置TextBox的WPF。 Visual Studio's built-in text editor has many advanced features related to code editing but is not available separately from Visual Studio.
Visual Studio的内置文本编辑器具有许多与代码编辑相关的高级功能,但不能单独从Visual Studio中获得。
There are many open-source and componentware text editor controls available for WPF that include region collapsing. WPF有许多开源和组件文本编辑器控件,包括区域折叠。 I suggest you download AvalonEdit or any of the text editor controls listed in this answer to see how it is done, and either reuse the control you downloaded or roll your own using similar techniques.
我建议您下载AvalonEdit或本答案中列出的任何文本编辑器控件以查看它是如何完成的,并重用您下载的控件或使用类似技术自行编辑。
The technique most text editors use for region collapsing is to include a "outline hidden" flag in the data structure maintained for every line in addtion to an "is outline start" flag, an "outline end" pointer, and a "nesting level". 大多数文本编辑器用于区域折叠的技术是在数据结构中包括“轮廓隐藏”标志,该标志为“是轮廓开始”标志,“轮廓结束”指针和“嵌套级别”添加的每一行维护。 。 By keeping these up to date and having the display templates honor them by drawing the proper icons/buttons and/or hiding the line, you can get the effect you need quite easily.
通过保持这些最新并让显示模板通过绘制正确的图标/按钮和/或隐藏线来尊重它们,您可以非常轻松地获得所需的效果。 Obviously this relies on your text editor's data structure tracking and displaying each line independently, which requires additional logic for selection, navigation, etc that is not included in WPF.
显然,这取决于您的文本编辑器的数据结构跟踪和独立显示每一行,这需要额外的逻辑选择,导航等未包含在WPF中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.