1

我从这里更改了我的超链接:

   <HyperlinkButton x:Name="hyperlinkButtonManageInvitations" Margin="24"
                    Grid.Row="1" Tap="HyperlinkButtonManageInvitations_OnTap">
       Manage Invitations
   </HyperlinkButton>

...对此:

    <HyperlinkButton x:Name="hyperlinkButtonManageInvitations"
                     BorderBrush="DarkOrange" Margin="24" Grid.Row="1"
                     Tap="HyperlinkButtonManageInvitations_OnTap">
        Manage Invitations
    </HyperlinkButton>

...并且没有视觉变化 - 没有添加边框。所以我然后尝试调整更多属性,如下所示:

    <HyperlinkButton x:Name="hyperlinkButtonManageInvitations"
                     BorderBrush="DarkOrange" Margin="24" Grid.Row="1"
                     Tap="HyperlinkButtonManageInvitations_OnTap"
                     BorderThickness="4" OpacityMask="Black">
        Manage Invitations
    </HyperlinkButton>

……还是不行。我不了解添加边框的哪一部分?

更新

我的超链接按钮现在是:

    <HyperlinkButton x:Name="hyperlinkButtonManageInvitations" Style="{StaticResource BorderedHyperlinkButtonStyle}" BorderThickness="5" BorderBrush="Red" Foreground="DarkOrange" Margin="24" Grid.Row="1" Tap="HyperlinkButtonManageInvitations_OnTap" Content="Manage Invitations">
    </HyperlinkButton>

...我将下面提供的样式添加到 App.xaml 部分,但我现在仍然看到有问题的超链接按钮周围的边框。

更新 2

它现在就在那里——它“突然”出现了;我猜 xaml 渲染器可能会时不时地吸收缓慢。或者在使用新添加的样式时,需要先重新加载项目,或者……???

4

1 回答 1

5

这与 HyperlinkBut​​ton 控件模板有关;如果你去 Blend 并创建一个控制模板的副本来编辑,你会得到这样的东西:

<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" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TextElement"/>
          </Storyboard>
        </VisualState>
        <VisualState x:Name="Disabled">
          <Storyboard>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="TextElement">
              <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" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Content}" TextDecorations="Underline" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    </Border>
  </Border>
</ControlTemplate>

因此,您可以在这里检查控件 BorderBrush 和 BorderThickness 属性是否没有 TemplateBinding。

要解决您的问题,只需复制此样式并将其插入页面/应用程序资源中:

<Style x:Key="BorderedHyperlinkButtonStyle" TargetType="HyperlinkButton">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="HyperlinkButton">
        <Border Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
          <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
              <VisualState x:Name="Normal"/>
              <VisualState x:Name="MouseOver"/>
              <VisualState x:Name="Pressed">
                <Storyboard>
                  <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TextElement"/>
                </Storyboard>
              </VisualState>
              <VisualState x:Name="Disabled">
                <Storyboard>
                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="TextElement">
                    <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" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Content}" TextDecorations="Underline" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
          </Border>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

然后,在你想要的带边框的 HyperlinkBut​​ton 上,设置如下:

<HyperlinkButton Style="{StaticResource BorderedHyperlinkButtonStyle}" BorderThickness="5" BorderBrush="Red" />

随意编辑 BorderThickness 和 BorderBrush!

于 2012-12-31T16:58:05.107 回答