我不知道另一种方法,但在 XAML 中设置 ControlTemplate。但是你可以在 C# 中使用它:
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
};
希望这可以帮助