我如何添加下划线到在Silverlight HyperlinkButton? [英] How can I add an underline to a HyperlinkButton in Silverlight?
问题描述
看来我可以以同样的方式格式化HyperlinkButton我可以格式化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 HyperlinkButton?
推荐答案
如果你只需要一个静态的下划线(无鼠标悬停),你应该只使用一个TextBlock的内容的HyperlinkButton。由于HyperlinkButton是一个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作为一个HyperlinkButton内容:
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#中的代码 - 设置HyperlinkButton的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.
由于大卫说,编辑控件模板肯定会努力风格HyperlinkButton根据自己的喜好,但使用实际强调的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 HyperlinkButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!