首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在MouseEnter上为TextBlock加下划线

在MouseEnter事件上为TextBlock添加下划线,可以通过使用TextBlock的TextDecorations属性来实现。以下是一个简单的示例,展示了如何在TextBlock上添加下划线:

代码语言:xaml
复制
<TextBlock Text="Hello, world!" MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave"/>

在代码后台中,我们需要添加两个事件处理程序,一个用于MouseEnter事件,另一个用于MouseLeave事件。这些事件处理程序将分别添加和删除下划线:

代码语言:csharp
复制
private void TextBlock_MouseEnter(object sender, MouseEventArgs e)
{
    TextBlock textBlock = sender as TextBlock;
    textBlock.TextDecorations = TextDecorations.Underline;
}

private void TextBlock_MouseLeave(object sender, MouseEventArgs e)
{
    TextBlock textBlock = sender as TextBlock;
    textBlock.TextDecorations = null;
}

这样,当鼠标悬停在TextBlock上时,它将显示下划线,当鼠标离开时,下划线将被删除。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券