如何在选择TextBlock中的文本的位置显示弹出按钮 [英] How to show a flyout in where the text in a TextBlock is selected

查看:89
本文介绍了如何在选择TextBlock中的文本的位置显示弹出按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的TextBlock中添加弹出按钮,当我在TextBlock中选择文本时,弹出窗口将显示在选定的位置(有点像Microsoft Edge中的阅读模式",当您在阅读中选择文本时)模式下,将会弹出一个窗口,显示单词的定义).但是我不知道如何.我尝试使用SelectionChanged,但是此事件传递的参数没有可用于设置flyout的位置.那我该怎么办呢? 此外,我想知道SelectionFlyout的用途是什么?我认为这可以帮助我. 这是我的代码:

I want to add a flyout to my TextBlock, and when I select the text in the TextBlock, the flyout will show up at the selected (kind of like Reading Mode in Microsoft Edge, when you select the text in reading mode, there will be a flyout show the word's definition). But I don't know how. I've tried using the SelectionChanged, but the parameters that this event passes don't have an position that I can use to set the flyout. So how can I do that? Besides, I'm wondering what SelectionFlyout is for? I thought it could help me. Here was my code:

<TextBlock x:Name="webviewtest" Grid.Row="1" Text="This is a select-flyout test." FontSize="300" IsTextSelectionEnabled="true" >
    <TextBlock.SelectionFlyout>
        <Flyout>
            <TextBlock Text="this is the flyout"></TextBlock>
        </Flyout>
    </TextBlock.SelectionFlyout>
</TextBlock>

当我选择文本时,弹出按钮从未显示出来.显然我一直在用错它.因此,我检查了 Microsoft Docs 并说

And when I selected text, the flyout never showed up. It's obviously that I have been using it wrong. So I checked the Microsoft Docs and it said

获取或设置在选择文本时显示的弹出窗口;如果未显示弹出窗口,则为null.

Gets or sets the flyout that is shown when text is selected, or null if no flyout is shown.

我在网上找不到有关此的任何示例.

And I can't find any samples about this online.

推荐答案

您需要使用RichTextBlock替换TextBlock,并且平台为17134和更持久.

You need to use RichTextBlock to replace TextBlock and the platform is 17134 and laster.

    <RichTextBlock HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   IsTextSelectionEnabled="True">
        <RichTextBlock.ContextFlyout>
            <Flyout>
                <TextBlock Text="flyout" />
            </Flyout>
        </RichTextBlock.ContextFlyout>
        <RichTextBlock.SelectionFlyout>
            <Flyout>
                <TextBlock Text="this is the flyout" />
            </Flyout>
        </RichTextBlock.SelectionFlyout>
        <Paragraph>
            welcome to blog.lindexi.com that has many blogs
        </Paragraph>
    </RichTextBlock>

SelectionFlyout与您保持联系. TextBlock.SelectionFlyout不起作用·问题#452·Microsoft/microsoft-ui-xaml

The SelectionFlyout is work in touch. TextBlock.SelectionFlyout doesn't work · Issue #452 · Microsoft/microsoft-ui-xaml

github

这篇关于如何在选择TextBlock中的文本的位置显示弹出按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆