在 WPF Richt-TextBox 中将鼠标悬停在超链接上时设置光标

我有一个来自 Xtended WPF Toolkit 的 Rich-Text-Box 来显示绑定到一些 .rtf 文件的文本。我想要“只读”框,但同时我希望文件中的超链接处于活动状态并且可供用户点击。为了实现这一点,我创建了这样的框:


<xctk:RichTextBox x:Name="richTextBox" Cursor="Arrow" VerticalAlignment="Stretch" Text="{Binding text}"  Focusable="False" IsDocumentEnabled="True">

    <xctk:RichTextBox.Resources>

        <Style TargetType="Hyperlink">

            <Setter Property="Cursor" Value="Arrow" />

            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="Hyperlink_MouseLeftButtonDown"/>

    </Style>

</xctk:RichTextBox.Resources>

</xctk:RichTextBox>

几乎一切正常,我可以单击富文本框中的链接,但是当鼠标悬停在链接上时,光标会变成“文本选择”光标(就像您将鼠标悬停在文本输入字段上一样在这里),这看起来很愚蠢。所以看起来这条线


<Setter Property="Cursor" Value="Arrow" />

正在被忽视。有没有什么办法解决这一问题?


陪伴而非守候
浏览 326回答 2
2回答

慕桂英4014372

您应该尝试使用此属性ForceCursor="true"在您的 RichTextBox 上

斯蒂芬大帝

尝试向将属性设置为的IsMouseOver触发器添加:StyleIsEnabledfalse<Style TargetType="Hyperlink">&nbsp; &nbsp; <EventSetter Event="PreviewMouseLeftButtonDown" Handler="Hyperlink_MouseLeftButtonDown"/>&nbsp; &nbsp; <Style.Triggers>&nbsp; &nbsp; &nbsp; &nbsp; <Trigger Property="IsMouseOver" Value="True">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Setter Property="IsEnabled" Value="False" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Setter Property="Foreground" Value="Red" />&nbsp; &nbsp; &nbsp; &nbsp; </Trigger>&nbsp; &nbsp; </Style.Triggers></Style>
打开App,查看更多内容
随时随地看视频慕课网APP