简体   繁体   English

Wpf- visual studio中的文本框如何折叠区域以及如何在文本编辑器中实现它?

[英]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.

相关问题 Wpf-如何在代码中获取普通 TextBox 的 LineHeight? - Wpf- How can I get the LineHeight of a normal TextBox in code? WPF-如何使用我在用户控件中声明并填充我的 MainWindow 的列表? - WPF- How can i use a List that i declare and fill in my MainWindow in a Usercontrol? WPF-列表视图。 如何使我的内容垂直和水平显示? - WPF- List View. How can I enable my content to display Vertically and Horizontally? WPF-如何绑定两个Listbox的SelectedValue属性? - WPF- How can I bind to SelectedValue properties of two Listboxes? WPF-为什么无法选择我的自定义文本框? - WPF- Why can't my custom textbox be selected? 如何在 Visual Studio WPF 上创建这种模型?[TreeList to TextBox] - How can I create this kind of model on Visual Studio WPF?[TreeList to TextBox] Visual Studio:如何使用WPF编写编辑器扩展 - Visual Studio: How to write Editor Extensions with WPF 如何加快Visual Studio 2010文本编辑器的渲染速度? - How can I speed up Visual Studio 2010 text editor render speed? WPF-如何获取触发TreeViewItem.Loaded事件的TreeViewItem? - Wpf- How can I get the TreeViewItem that triggered the TreeViewItem.Loaded event? WPF-如何单击时阻止控件模板中的弹出窗口关闭? - WPF- How can I stop a popup in a control template from closing when clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM