![](/img/trans.png)
[英]Windows Phone 7 Silverlight DataTemplate HyperlinkButton content
[英]Silverlight HyperlinkButton only content clickable
我的页面上有一个HyperlinkButton,内容仅为纯文本。 但是,如下图所示,HyperlinkButton通常比实际内容宽。 这可能会造成混淆,因为人们只希望实际单击链接时会发生某些事情。
如何使HyperlinkButton与内容一样宽,或者仅使内容可单击? 我尝试设置样式,但是没有帮助。
感谢您的任何帮助。 Dominic Rooijackers
欢迎来到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>
学习愉快.. !! :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.