2012-10-13 20 views
7

RichTextBlock öğesinde bir köprü göstermek istiyorum, ancak aynı zamanda doğru görünmesini istiyorum. En yakın bunun ne almak mümkün oldum: BununRichTextBlock'ta Köprüleri tamamen hizalanmamış olarak nasıl yapabilirim?

How I was able to get it to look

XAML aşağıda yapıştırılır - esasen, ben InlineUIElement kullanmak ve düğme çevresindeki tüm yabancı maddelerin alınması kaynak düzenlenebilir. Bir şey mi eksik? Bunu çözmenin tek gerçek yolu kendi köprümümü açmak mı? StandardStyles.xaml ile birlikte içinde TextButtonStyle bakarak çalıştı

<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> 

cevap

6

sizi var: Burada

zengin metin bloğu için XAML var:

<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> 

Ve burada nuked kaynak için XAML var standart VS şablonları? Kendi köprüsünüzü oluşturmak zorunda değilsiniz. Metroda bir kontrol şablonunu tamamen değiştirebilirsiniz, böylece istediğiniz işlevsellikte bir kontrol olduğunda işlevselliği yeniden üretmeye gerek yoktur.

Düzenleme

: Ben TextButtonStyle şablonu alıp Margin="3,-20,3,0" için marjı değiştirdi ve daha sonra FontSize="14" eklendi.

Şimdi şuna benzer:

enter image description here

bugüne kadar kapalı TextButtonStyle şablonda TextBlock üzerine TextBlock şablon şöyle olmasıdır nedeni:

<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> 

Bildirimi sınır. Bu yüzden düzeltmek için ya ebeveynte negatif bir marj yaratmalıydık (benim yaptığım gibi) ya da PageSubheaderTextStyle'daki marjı değiştirmemiz gerekiyordu.

+0

Evet - textButtonStyle kullanarak aynı tam etkiyi verir ... –

+0

@ShaharPrish Edit my edit. İstediğiniz etkiyi almak için şablonu hafifçe değiştirmeniz yeterlidir. – mydogisbox

+0

Teşekkürler. Bu daha iyi çalışıyor gibi görünüyor - hala iyi görünmüyor, ama en azından hizalanmış. "Sadece işe" diliyorum. –