C# WP-如何以编程方式删除hyperlinkButton中的下划线?
我在C#中开发了一个超链接按钮。hyperlinkButton中的下划线让我恼火。我不知道如何移除它。帮我去掉下划线,我需要用C#来回答。[这是WP8应用程序]C# WP-如何以编程方式删除hyperlinkButton中的下划线?,c#,windows-phone-8,C#,Windows Phone 8,我在C#中开发了一个超链接按钮。hyperlinkButton中的下划线让我恼火。我不知道如何移除它。帮我去掉下划线,我需要用C#来回答。[这是WP8应用程序] HyperlinkButton hyperlinkButton = new HyperlinkButton() { Content = "Click me", HorizontalAlignment = HorizontalAlignment.Left, NavigateU
HyperlinkButton hyperlinkButton = new HyperlinkButton()
{
Content = "Click me",
HorizontalAlignment = HorizontalAlignment.Left,
NavigateUri = new Uri("http://my-link-com", UriKind.Absolute)
};
引用
可以直接设置特性,也可以使用样式:
<Style TargetType="{x:Type Hyperlink}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="DarkSlateBlue" />
</Trigger>
</Style.Triggers>
<Setter Property="Foreground" Value="SteelBlue" />
<Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
</Style>
除了在XAML中设置ControlTemplate,我不知道其他方法。但是你可以在C中使用它:
var str=“”+
" " +
"";
var template=(ControlTemplate)XamlReader.Load(str);
HyperlinkButton HyperlinkButton=新建HyperlinkButton()
{
Content=“单击我”,
水平对齐=水平对齐。左,
NavigateUri=新Uri(“http://my-link-com“,乌里金。绝对),
模板=模板
};
希望这有帮助你能发布你得到的代码结果吗?我不知道c#能做到这一点,但CSS能做到!你用什么风格?@nilesh是WP8app@RobertKenny这是一个WP8应用程序,这个答案用XAML表示。我需要C#@user2655873的答案我不确定C#的语法,但你应该能够找到你的对象的
TextBlock
或textdemotions
属性。HyperlinkButton1.Template=Template代码>我应该把这个放在哪里?
var str = "<ControlTemplate TargetType=\"HyperlinkButton\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
" <TextBlock HorizontalAlignment=\"{TemplateBinding HorizontalContentAlignment}\" Text=\"{TemplateBinding Content}\" VerticalAlignment=\"{TemplateBinding VerticalContentAlignment}\"/>" +
"</ControlTemplate>";
var template = (ControlTemplate)XamlReader.Load(str);
HyperlinkButton hyperlinkButton = new HyperlinkButton()
{
Content = "Click me",
HorizontalAlignment = HorizontalAlignment.Left,
NavigateUri = new Uri("http://my-link-com", UriKind.Absolute),
Template = template
};