2012-10-13 13 views
7

Chcę móc wyświetlić hiperłącze w elemencie RichTextBlock, ale chcę też, aby wyglądał prawidłowo. Najbliżej byłem w stanie dostać się do to:Jak sprawić, aby hiperłącza w RichTextBlock nie były całkowicie nieprzypisane?

How I was able to get it to look

XAML tego jest wklejony poniżej - zasadniczo używam InlineUIElement a ja edytowany zasób, aby usunąć cały CRUD wokół przycisku. Czy czegoś brakuje? Czy jedynym sposobem na rozwiązanie tego problemu jest przeniesienie mojego hiperłącza?

Oto XAML dla bogatego bloku tekstowego:

<RichTextBlock VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="14"> 
    <Paragraph>I just want this 
     <InlineUIContainer> 
      <HyperlinkButton Style="{StaticResource HyperlinkButtonStyle1}">Hyperlink</HyperlinkButton> 
     </InlineUIContainer> 
     to not look like crap 
    </Paragraph> 
</RichTextBlock> 

A oto XAML dla nuked zasobu:

<Style x:Key="HyperlinkButtonStyle1" TargetType="HyperlinkButton"> 
    <Setter Property="Foreground" Value="{StaticResource HyperlinkForegroundThemeBrush}"/> 
    <Setter Property="Background" Value="{StaticResource HyperlinkButtonBackgroundThemeBrush}"/> 
    <!--<Setter Property="BorderBrush" Value="{StaticResource HyperlinkButtonBorderThemeBrush}"/>--> 
    <Setter Property="BorderThickness" Value="0"/> 
    <Setter Property="Padding" Value="0"/> 
    <Setter Property="HorizontalAlignment" Value="Left"/> 
    <Setter Property="VerticalAlignment" Value="Bottom"/> 
    <Setter Property="FontFamily" Value="Global User Interface"/> 
    <Setter Property="FontSize" Value="14"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="HyperlinkButton"> 
       <Grid> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="CommonStates"> 
          <VisualState x:Name="Normal"/> 
          <VisualState x:Name="PointerOver"> 
           <Storyboard> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource HyperlinkPointerOverForegroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Pressed"> 
           <Storyboard> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource HyperlinkPressedForegroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Disabled"> 
           <Storyboard> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource HyperlinkDisabledThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="FocusStates"> 
          <VisualState x:Name="Focused"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualWhite"/> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualBlack"/> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Unfocused"/> 
          <VisualState x:Name="PointerFocused"/> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" VerticalAlignment="Bottom"> 
         <ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0" VerticalAlignment="Bottom"/> 
        </Border> 
        <Rectangle x:Name="FocusVisualWhite" IsHitTestVisible="False" Opacity="0" StrokeDashOffset="1.5" StrokeEndLineCap="Square" Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}" StrokeDashArray="1,1"/> 
        <Rectangle x:Name="FocusVisualBlack" IsHitTestVisible="False" Opacity="0" StrokeDashOffset="0.5" StrokeEndLineCap="Square" Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}" StrokeDashArray="1,1"/> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

Odpowiedz

6

próbowałeś patrząc na TextButtonStyle w StandardStyles.xaml dołączone do standardowe szablony VS? Nie powinieneś tworzyć własnego hiperłącza. W metrze można całkowicie zastąpić szablon kontrolki, więc nie ma potrzeby odtwarzania funkcji, gdy istnieje już kontrola z pożądaną funkcjonalnością.

Edytuj: Wziąłem szablon TextButtonStyle i zmieniłem margines na Margin="3,-20,3,0", a następnie dodano FontSize="14".

Teraz wygląda to tak:

enter image description here

Powodem było tak daleko, że szablon TextBlock na TextBlock w szablonie TextButtonStyle wygląda następująco:

<Style x:Key="PageSubheaderTextStyle" TargetType="TextBlock" BasedOn="{StaticResource SubheaderTextStyle}"> 
    <Setter Property="TextWrapping" Value="NoWrap"/> 
    <Setter Property="VerticalAlignment" Value="Bottom"/> 
    <Setter Property="Margin" Value="0,0,0,40"/> 
</Style> 

Wskazówka Margines. Aby to naprawić, musieliśmy stworzyć rodzicowi margines ujemny (tak jak ja) lub po prostu zmienić marżę na PageSubheaderTextStyle.

+0

Tak - użycie textButtonStyle daje ten sam dokładny efekt ... –

+0

@ShaharPrish Zobacz moją zmianę. Trzeba tylko nieznacznie poprawić szablon, aby uzyskać pożądany efekt. – mydogisbox

+0

Dzięki. To wydaje się działać lepiej - nadal nie wygląda dobrze, ale przynajmniej jest wyrównane. Chciałbym, żeby "po prostu zadziałało". –

Powiązane problemy