none
Unterstreichung bei HyperlinkButton entfernen? RRS feed

  • Frage

  • Hey Leute,

    wie kann ich die Unterschreichung bei einem HyperlinkButton entfernen?

    Bin ratlos ^^

    Danke schonmal

    René

    Mittwoch, 1. Juni 2011 09:51

Antworten

  • Hallo Renè,

    einfach die Textdecoration auf "None" oder gleich ganz weglassen, dann das Ganze als Resource "HyperlinkButtonStyle1" und dem HyperlinkButton zuweisen.

    <phone:PhoneApplicationPage
        x:Class="DominikErnst.PeriodicTable.About"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True"
        xmlns:my="clr-namespace:DominikErnst.Library.Controls;assembly=DominikErnst.Library">

     <phone:PhoneApplicationPage.Resources>
      <Style x:Key="HyperlinkButtonStyle1" TargetType="HyperlinkButton">
       <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
       <Setter Property="Background" Value="Transparent"/>
       <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
       <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" 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>
            <VisualStateGroup x:Name="FocusStates">
             <VisualState x:Name="Unfocused"/>
             <VisualState x:Name="Focused"/>
            </VisualStateGroup>
           </VisualStateManager.VisualStateGroups>
           <Border Background="{TemplateBinding Background}" Margin="{StaticResource PhoneHorizontalMargin}" Padding="{TemplateBinding Padding}">
            <TextBlock x:Name="TextElement" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Content}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextDecorations="None"/>
           </Border>
          </Border>
         </ControlTemplate>
        </Setter.Value>
       </Setter>
      </Style>
     </phone:PhoneApplicationPage.Resources>

        <!--LayoutRoot contains the root grid where all other page content is placed-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!--TitlePanel contains the name of the application and page title-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12">
                <TextBlock x:Name="ApplicationTitle" Text="DOMINIK ERNST" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="about" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>

            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentGrid" Grid.Row="1">
                 <HyperlinkButton Content="Hello World" Margin="0,112,51,0" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{StaticResource HyperlinkButtonStyle1}"  />
            </Grid>
        </Grid>

    </phone:PhoneApplicationPage>

     


    Regards,

    Dominik A. Ernst
    www.dominik-ernst.de, www.wp7-software.net
    Donnerstag, 2. Juni 2011 11:33

Alle Antworten

  • Wenn du keine Unterstreichung willst, nimm doch ein TextBlock-Element und löse eine Aktion mit MouseLeftButtonDown aus.
    Mittwoch, 1. Juni 2011 12:16
  • Hallo Rene,

    die einzigste Möglichkeit am HyperlinkButton direkt etwas zu ändern, ist die Verwendung eines ControlTemplates. für das Content Control. Dort musst Du die Style Eigenschaften des TextBlockes entsprechend verändern.

    Schöne Grüße

    Oliver

    Mittwoch, 1. Juni 2011 15:32
  • Hallo Renè,

    einfach die Textdecoration auf "None" oder gleich ganz weglassen, dann das Ganze als Resource "HyperlinkButtonStyle1" und dem HyperlinkButton zuweisen.

    <phone:PhoneApplicationPage
        x:Class="DominikErnst.PeriodicTable.About"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True"
        xmlns:my="clr-namespace:DominikErnst.Library.Controls;assembly=DominikErnst.Library">

     <phone:PhoneApplicationPage.Resources>
      <Style x:Key="HyperlinkButtonStyle1" TargetType="HyperlinkButton">
       <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
       <Setter Property="Background" Value="Transparent"/>
       <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
       <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" 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>
            <VisualStateGroup x:Name="FocusStates">
             <VisualState x:Name="Unfocused"/>
             <VisualState x:Name="Focused"/>
            </VisualStateGroup>
           </VisualStateManager.VisualStateGroups>
           <Border Background="{TemplateBinding Background}" Margin="{StaticResource PhoneHorizontalMargin}" Padding="{TemplateBinding Padding}">
            <TextBlock x:Name="TextElement" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Content}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextDecorations="None"/>
           </Border>
          </Border>
         </ControlTemplate>
        </Setter.Value>
       </Setter>
      </Style>
     </phone:PhoneApplicationPage.Resources>

        <!--LayoutRoot contains the root grid where all other page content is placed-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!--TitlePanel contains the name of the application and page title-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12">
                <TextBlock x:Name="ApplicationTitle" Text="DOMINIK ERNST" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="about" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>

            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentGrid" Grid.Row="1">
                 <HyperlinkButton Content="Hello World" Margin="0,112,51,0" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{StaticResource HyperlinkButtonStyle1}"  />
            </Grid>
        </Grid>

    </phone:PhoneApplicationPage>

     


    Regards,

    Dominik A. Ernst
    www.dominik-ernst.de, www.wp7-software.net
    Donnerstag, 2. Juni 2011 11:33