简体   繁体   English

'Run'元素扩展的边框

[英]Border around extension of 'Run' element

I'm creating a WPF application which shows a list of styled messages. 我正在创建一个WPF应用程序,其中显示了样式化消息列表。 My goal is to have the contents of multiple styled messages selectable, similar to how you can in Skype: 我的目标是可以选择多个样式化消息的内容,类似于在Skype中的方式:

Skype样本

Currently, I have a ListBox which contains an extension of ListBoxItem that is styled to my needs: 目前,我有一个ListBox,其中包含一个ListBoxItem扩展名,该扩展名适合我的需求:

在此处输入图片说明

However, this method does not satisfy my goal of being able to select the text of multiple messages at the same time. 但是,这种方法不能满足我能够同时选择多个消息的文本的目标。 It is only possible to select the text inside one message. 只能在一条消息中选择文本。

I also tried to put my custom elements inside a RichTextBox control within BlockUIContainer s (which is what I suspect I will end up having to use), but the text inside each element cannot be selected, only the entire element: 我还尝试将自定义元素放在BlockUIContainer的RichTextBox控件内(这是我怀疑最终不得不使用的控件),但是无法选择每个元素内的文本,只能选择整个元素:

在此处输入图片说明

Next, I attempted to extend the "Run" element, but I cannot figure out how to put a border around it to style an individual message. 接下来,我尝试扩展“运行”元素,但无法弄清楚如何在其周围放置边框以设置单个消息的样式。

<Run.Style>
    <Style TargetType="{x:Type Run}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Run}">
                    <Border Background="{TemplateBinding Background}" x:Name="Bd" CornerRadius="2">
                        <ContentPresenter />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Run.Style>

With this XAML, I tried to surround the content of the Run using a template, a border element, and a content presenter. 使用此XAML,我尝试使用模板,边框元素和内容演示者来包围Run的内容。 However, the Run control does not appear to support templates. 但是,运行控件似乎不支持模板。

If anybody could point me in the right direction, that would be greatly appreciated. 如果有人能指出我正确的方向,那将不胜感激。

I don't know if this will help you but is just another idea... 我不知道这是否对您有帮助,但这只是另一个主意...

Use one text control with transparent background so you can select all the text at once. 使用一个具有透明背景的文本控件,以便您可以一次选择所有文本。 Then you have to draw rectangles behind the text blocks. 然后,您必须在文本块后面绘制矩形。 Like an optical ilussion. 像是光学错觉。 The challenge here is calculating the exactly size of the text rectangle box and the text allignment. 这里的挑战是计算文本矩形框和文本分配的确切大小。 My idea is having a predefined sizes and positions design (left text box, right text box, date, etc) so the size and positioning calculations are easier. 我的想法是具有预定义的尺寸和位置设计(左侧文本框,右侧文本框,日期等),因此尺寸和位置计算更容易。

Another idea is play with the mouse and/or selection events. 另一个想法是玩鼠标和/或选择事件。 During the user text selection replace it programatically with your own selection. 在用户文本选择期间,以编程方式将其替换为您自己的选择。 The user will think that is he who is selecting the text but is the application who is doing it. 用户会认为选择文本的是他,但是选择文本的是应用程序。 Another illusion... 另一个错觉

I hope you could resolve it. 希望您能解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM