Silverlight HyperlinkButton仅可单击内容
我的页面上有一个超链接按钮,内容只是纯文本。 但是,如下图所示,HyperlinkButton通常比实际内容更宽。 这可能令人困惑,因为人们只希望在实际点击链接时发生一些事情 如何使HyperlinkButton与内容一样宽,或仅使内容可单击? 我试过设置样式,但没用 谢谢你的帮助。 多米尼克·鲁伊阿克斯Silverlight HyperlinkButton仅可单击内容,silverlight,Silverlight,我的页面上有一个超链接按钮,内容只是纯文本。 但是,如下图所示,HyperlinkButton通常比实际内容更宽。 这可能令人困惑,因为人们只希望在实际点击链接时发生一些事情 如何使HyperlinkButton与内容一样宽,或仅使内容可单击? 我试过设置样式,但没用 谢谢你的帮助。 多米尼克·鲁伊阿克斯 欢迎来到stackoverflow 对于您的问题,我想说您在使用样式进行此操作方面是正确的。您所要做的只是从超链接的默认样式中删除视觉状态,并删除不必要的超链接元素。您可以使用Expressi
欢迎来到stackoverflow 对于您的问题,我想说您在使用样式进行此操作方面是正确的。您所要做的只是从超链接的默认样式中删除视觉状态,并删除不必要的超链接元素。您可以使用Expression Blend在几分钟内完成此操作。现在我让你的生活更轻松了。您可以使用以下超链接样式继续
<Style x:Key="ContentPresenterStyle1" TargetType="ContentPresenter"/>
<Style x:Key="HyperlinkButtonStyle1" TargetType="HyperlinkButton">
<Setter Property="Foreground" Value="#FF73A9D8"/>
<Setter Property="Padding" Value="2,0,2,0"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="HyperlinkButton">
<Grid Background="{TemplateBinding Background}" Cursor="{TemplateBinding Cursor}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Pressed"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<VisualStateManager.CustomVisualStateManager>
<ei:ExtendedVisualStateManager/>
</VisualStateManager.CustomVisualStateManager>
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Style="{StaticResource ContentPresenterStyle1}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
祝你学习愉快 有多种方式,HorizontalAlignment=Left,Width=Auto,或者还有很多其他方式,如果您想在模板级别执行此操作,只需添加即可。