2013-07-07 102 views
0

我正在使用Blend + Sketchflow Preview for Visual Studio 2012,我想從HyperlinkBut​​ton刪除下劃線。刪除HyperlinkBut​​ton中的下劃線

這裏是我的代碼:

<HyperlinkButton x:Name="PoliciesTxt" Content="Policies" FontSize="18.667" Foreground="#FF003366" NavigateUri="http://google.com" FontWeight="Bold" CharacterSpacing="-1"/> 

我使用TextDecorations屬性已經嘗試過,但它並沒有在這個版本XAML的存在。

任何想法?

回答

1

添加以下Resrouce到你的頁面(在我的情況我剛剛把它添加到的App.xaml頁)

<!--Application Resources--> 
<Application.Resources> 
<Style x:Key="HyperlinkButtonStyle" TargetType="HyperlinkButton"> 
<Setter Property="Foreground" Value="White"/> 
<Setter Property="Background" Value="Transparent"/> 
<Setter Property="FontSize" Value="16"/> 
<Setter Property="Padding" Value="0"/> 
<Setter Property="Template"> 
<Setter.Value> 
<ControlTemplate TargetType="HyperlinkButton"> 
<Border Background="Transparent"> 
<VisualStateManager.VisualStateGroups> 
<VisualStateGroup x:Name="CommonStates"> 
<VisualState x:Name="Normal"/> 
<VisualState x:Name="MouseOver"/> 
<VisualState x:Name="Pressed"> 
<Storyboard> 
<DoubleAnimation Duration="0" Storyboard.TargetName="TextElement" 
Storyboard.TargetProperty="Opacity" To="0.5" /> 
</Storyboard> 
</VisualState> 
<VisualState x:Name="Disabled"> 
<Storyboard> 
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextElement" 
Storyboard.TargetProperty="Foreground"> 
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" /> 
</ObjectAnimationUsingKeyFrames> 
</Storyboard> 
</VisualState> 
</VisualStateGroup> 
</VisualStateManager.VisualStateGroups> 
<Border Background="{TemplateBinding Background}" Margin="{StaticResource 
PhoneHorizontalMargin}" Padding="{TemplateBinding Padding}" > 
<TextBlock x:Name="TextElement" Text="{TemplateBinding Content}" HorizontalAlignment=" 
{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding 
VerticalContentAlignment}" TextWrapping="Wrap" TextDecorations="none"/> 
</Border> 
</Border> 
</ControlTemplate> 
</Setter.Value> 
</Setter> 
</Style> 
</Application.Resources> 

現在,所有你需要做的是刪除一個HyperlinkBut​​ton控制到頁面上,設置風格如下:

<HyperlinkButton Style="HyperlinkButtonStyle" /> 
2

您必須更改默認樣式HyperlinkBut​​ton,複製下面的代碼在您的這個App.xaml文件。

首先,你必須在App.xaml中添加下面的命名空間

的xmlns:VSM = 「CLR的命名空間:System.Windows;裝配= System.Windows」

<Application.Resources> 

     <Style x:Key="HyperlinkButtonStyle" x:Name="HyperlinkButtonStyle" 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 Cursor="{TemplateBinding Cursor}" Background="{TemplateBinding Background}"> 
          <vsm:VisualStateManager.VisualStateGroups> 
           <vsm:VisualStateGroup x:Name="CommonStates"> 
            <vsm:VisualState x:Name="Normal"/> 
            <vsm:VisualState x:Name="MouseOver"> 
             <Storyboard> 
              <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UnderlineTextBlock" Storyboard.TargetProperty="Visibility" Duration="0"> 
               <DiscreteObjectKeyFrame KeyTime="0"> 
                <DiscreteObjectKeyFrame.Value> 
                 <Visibility>Visible</Visibility> 
                </DiscreteObjectKeyFrame.Value> 
               </DiscreteObjectKeyFrame> 
              </ObjectAnimationUsingKeyFrames> 
             </Storyboard> 
            </vsm:VisualState> 
            <vsm:VisualState x:Name="Pressed"> 
             <Storyboard> 
              <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UnderlineTextBlock" Storyboard.TargetProperty="Visibility" Duration="0"> 
               <DiscreteObjectKeyFrame KeyTime="0"> 
                <DiscreteObjectKeyFrame.Value> 
                 <Visibility>Visible</Visibility> 
                </DiscreteObjectKeyFrame.Value> 
               </DiscreteObjectKeyFrame> 
              </ObjectAnimationUsingKeyFrames> 
             </Storyboard> 
            </vsm:VisualState> 
            <vsm:VisualState x:Name="Disabled"> 
             <Storyboard> 
              <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DisabledOverlay" Storyboard.TargetProperty="Visibility" Duration="0"> 
               <DiscreteObjectKeyFrame KeyTime="0"> 
                <DiscreteObjectKeyFrame.Value> 
                 <Visibility>Visible</Visibility> 
                </DiscreteObjectKeyFrame.Value> 
               </DiscreteObjectKeyFrame> 
              </ObjectAnimationUsingKeyFrames> 
             </Storyboard> 
            </vsm:VisualState> 
           </vsm:VisualStateGroup> 
           <vsm:VisualStateGroup x:Name="FocusStates"> 
            <vsm:VisualState x:Name="Focused"> 
             <Storyboard> 
              <DoubleAnimation Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" Duration="0" To="1"/> 
             </Storyboard> 
            </vsm:VisualState> 
            <vsm:VisualState x:Name="Unfocused"/> 
           </vsm:VisualStateGroup> 
          </vsm:VisualStateManager.VisualStateGroups> 
          <TextBlock 
          x:Name="UnderlineTextBlock" 
          Text="{TemplateBinding Content}" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
          Margin="{TemplateBinding Padding}" 
          TextDecorations="Underline" 
          Visibility="Collapsed"/> 
          <TextBlock Canvas.ZIndex="1" 
          x:Name="DisabledOverlay" 
          Text="{TemplateBinding Content}" 
          Foreground="#FFAAAAAA" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
          Margin="{TemplateBinding Padding}" 
          Visibility="Collapsed"/> 
          <ContentPresenter 
          x:Name="contentPresenter" 
          Content="{TemplateBinding Content}" 
          ContentTemplate="{TemplateBinding ContentTemplate}" 
          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          Margin="{TemplateBinding Padding}"/> 
          <Rectangle x:Name="FocusVisualElement" Stroke="#FF6DBDD1" StrokeThickness="1" Opacity="0" IsHitTestVisible="false" /> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

    </Application.Resources> 

,你也有將樣式應用於HyperlinkBut​​ton

<HyperlinkButton X:Name="Link" Content="Hola" Style="{StaticResource HyperlinkButtonStyle}"/> 
+0

這對我有用;) –