WPF(irc)聊天记录控件

发布于 2024-10-09 13:17:09 字数 449 浏览 0 评论 0原文

我正在尝试学习 WPF,并正在考虑创建一个简单的 IRC 客户端。最复杂的部分是创建聊天日志。我希望它看起来或多或少像 mIRC:

alt text

或 irssi:

alt text

重要的部分是文本应该是可选的,换行应该能够处理相当大的日志。

我可以提出的替代方案是:

  1. ScrollViewer 内的 StackPanel,其中每一行都是一个行
  2. ListView,因为这似乎更适合动态内容/数据绑定。
  3. 创建一个自己的控件来自行渲染。

是否有任何 WPF 专家对采取哪个方向以及从哪里开始有一些想法?

I'm trying to learn WPF and was thinking about creating a simple IRC client. The most complicated part is to create the chat log. I want it to look more or less like the one in mIRC:

alt text

or irssi:

alt text

The important parts are that the text should be selectable, lines should wrap and it should be able to handle quite large logs.

The alternatives that I can come up with are:

  1. StackPanel inside a ScrollViewer where each line is a row
  2. ListView, since that seems more suitable for dynamic content/data binding.
  3. Create an own control that does the rendering on its own.

Is there any WPF guru out there that has some ideas on which direction to take and where to start?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱你是孤单的心事 2024-10-16 13:17:09

我建议您从独立于 UI 的良好对象模型开始,然后尝试多行 TextBoxRichTextBox

这些是否足够将取决于您希望日志能够获得多长时间。如果遇到性能问题,您可能需要考虑虚拟化。

I suggest you start with a good object model independent of the UI, and then try a multi-line TextBox or a RichTextBox.

Whether these will suffice will depend on exactly how long you want the log to be able to get. If you run into performance issues, you may need to look at virtualization.

感情洁癖 2024-10-16 13:17:09

首先,您应该考虑是否只想选择整行(如在列表框中),或者是否想从行中选择某些字符(如在文本框中)。

对于第一种情况,我认为ListView甚至ListBox应该就足够了,它们在绑定到集合时都支持虚拟化,并且海量数据应该没有问题。 ScrollViewer 内的堆栈面板有点像在这种情况下重新发明轮子,在我看来,创建新控件并不是一个非常有灵感的方法(因为您想要的功能可以使用 WPF 中的现有控件来实现)。

在第二种情况下,如果您想选择行内的某些文本,或者如果您希望对日志中最长的行进行自动换行并希望选择换行行的各个部分,那么您需要使用更定向的控件关于显示文本。 Kent 已经建议使用 RichTextBox,我会添加 AvalonEdit 控件,甚至添加 WebBrowser 控件,您可以在其中直接修改其 HTMLDocument。

First of all, you should consider if you want to select only entire row (like in a listbox), or if you want to select certain characters from a row (like in a textbox).

In the first case, I think a ListView or even a ListBox should be enough, both of them support virtualization when bound to collection and there should be no problem with huge amounts of data. A stack panel inside a ScrollViewer is a little bit like reinventing the wheel for this case and creating a new control is not a very inspired approach in my opinion (as the functionality you want can be achieved with the existing controls, in WPF).

In the second case, if you want to select some text inside of a line, or if you want word wrapping for your longest lines in the log and want to select individual parts of the wrapped lines, then you need to use a control more oriented on displaying text. Kent already suggested a RichTextBox, I would add AvalonEdit control or even the WebBrowser control in which you directly modify its HTMLDocument.

同尘 2024-10-16 13:17:09

如果遇到性能问题,我建议也使用 RichTextBox,并将项目存储在日志文件或数据库中。
另一种解决方案是使用 WPF WebBrowser 控件并通过以下方式修改其 HTML 内容:

webBrowser.NavigateToString("<HTML><H2><B>This page comes using String</B><P></P></H2></HTML>");

有关使用 WebBrowser 控件的更多信息

I would suggest to use RichTextBox too, and store items in a log file or database, if you run into performance issues.
Another solution is to use the WPF WebBrowser control and modifiy its HTML content with:

webBrowser.NavigateToString("<HTML><H2><B>This page comes using String</B><P></P></H2></HTML>");

More information about using WebBrowser control

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文