我如何添加下划线到在Silverlight HyperlinkBut​​ton? [英] How can I add an underline to a HyperlinkButton in Silverlight?

查看:166
本文介绍了我如何添加下划线到在Silverlight HyperlinkBut​​ton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来我可以以同样的方式格式化HyperlinkBut​​ton我可以格式化TextBlock的:

It seems I can format a HyperlinkButton in the same way I can format a TextBlock:

HyperlinkButton hyperlinkButton = new HyperlinkButton();
hyperlinkButton.Content = "google";
hyperlinkButton.NavigateUri = new Uri("http://www.google.com");
hyperlinkButton.TargetName = "blank";
hyperlinkButton.Foreground = XamlHelpers.GetColorFromHex("555");
hyperlinkButton.TextDecoration = ... //error
hyperlinkButton.FontWeight = FontWeights.Bold;



不过,TextDecoration不会因为它在TextBlock中做工作。我得到在鼠标悬停自动下划线,但希望它有一个下划线之前鼠标悬停为好。

However, TextDecoration doesn't work as it does in TextBlock. I get an automatic underline upon mouseover but would like it to have an underline before mouseover as well.

我如何添加下划线到在Silverlight HyperlinkBut​​ton?

推荐答案

如果你只需要一个静态的下划线(无鼠标悬停),你应该只使用一个TextBlock的内容的HyperlinkBut​​ton。由于HyperlinkBut​​ton是一个ContentControl中它可以采取任何其他控制类型,它的内容(不仅仅是简单的字符串)。

If you just need a static underline (no mouseover effects) you should just use a TextBlock as the content of the HyperlinkButton. Since HyperlinkButton is a ContentControl it can take any other control type as it's content (more than just simple strings).

下面是一些XAML,这将让你带下划线的TextBlock作为一个HyperlinkBut​​ton内容:

Here is some XAML which will get you an underlined TextBlock as the content for a HyperlinkButton:

    <HyperlinkButton NavigateUri="http://google.com">
        <TextBlock Text="Google" TextDecorations="Underline" />
    </HyperlinkButton>

您应该能够创建您的TextBlock和C#中的代码 - 设置HyperlinkBut​​ton的Content属性后面还有,如果这是你在做什么。

You should be able to create your TextBlock and set the Content property of your HyperlinkButton with C# in code-behind as well if that is what you are doing.

由于大卫说,编辑控件模板肯定会努力风格HyperlinkBut​​ton根据自己的喜好,但使用实际强调的TextBlock如内容可以更简单,如果这是所有你需要做的少了很多XAML。

As David said, editing the ControlTemplate will certainly work to style a HyperlinkButton to your liking, but using an actual underlined TextBlock as content may be simpler and a lot less XAML if that is all you need to do.

这篇关于我如何添加下划线到在Silverlight HyperlinkBut​​ton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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