2012-03-12 24 views
0

將HyperlinkBut​​ton懸停在垂直StackPanel上時,會在HyperlinkBut​​ton下方控制幾個像素。這是一個奇怪的錯誤,我確信有一個修復程序,但我發現唯一的HyperlinkBut​​ton錯誤修復涉及到大量文本在懸停時渲染模糊,而不是這個定位錯誤。有沒有人遇到過這個?Silverlight:修復HyperlinkBut​​ton懸停錯誤?

XAML:

<Canvas x:Name="LayoutRoot"> 
    ... 
    <StackPanel x:Name="Article1" Style="{StaticResource ArticleContainer}" 
       Canvas.Top="46"> 

     <StackPanel Orientation="Horizontal"> 
      <Image x:Name="Article1Image" Style="{StaticResource ImageCategory}"/> 
      <TextBlock x:Name="Article1Title" Style="{StaticResource TitleText}"/> 
     </StackPanel> 

     <TextBlock x:Name="Article1Posted" Style="{StaticResource PostedText}"/> 

     <HyperlinkButton x:Name="Author1Link" Style="{StaticResource HLBStyling}"> 
      <TextBlock x:Name="Article1By" Style="{StaticResource AuthorText}"/> 
     </HyperlinkButton> 

     <TextBlock x:Name="Article1Content" Style="{StaticResource ContentText}"/> 

     <HyperlinkButton x:Name="Article1Link" Style="{StaticResource HLBStyling}"> 
      <TextBlock x:Name="Article1ReadMore" Style="{StaticResource ReadMoreText}"/> 
     </HyperlinkButton> 

    </StackPanel> 
    ... 
    </Canvas> 

的App.xaml:

<Style x:Key="ContentPanel" TargetType="Border"> 
     <Setter Property="Height" Value="427"/> 
     <Setter Property="Width" Value="250"/> 
     <Setter Property="Canvas.Top" Value="33"/> 
     <Setter Property="Canvas.Left" Value="0"/> 
     <Setter Property="Canvas.ZIndex" Value="1"/> 
    </Style> 

    <Style x:Key="ArticleContainer" TargetType="StackPanel"> 
     <Setter Property="Height" Value="195"/> 
     <Setter Property="Width" Value="230"/> 
     <Setter Property="Canvas.Left" Value="10"/> 
     <Setter Property="Canvas.ZIndex" Value="2"/> 
    </Style> 

    <Style x:Key="ImageCategory" TargetType="Image"> 
     <Setter Property="Width" Value="40"/> 
     <Setter Property="Height" Value="40"/> 
     <Setter Property="Margin" Value="5,5,5,0"/> 
    </Style> 

    <Style x:Key="TitleText" TargetType="TextBlock"> 
     <Setter Property="LineStackingStrategy" Value="BlockLineHeight"/> 
     <Setter Property="FontSize" Value="14"/> 
     <Setter Property="FontWeight" Value="SemiBold"/> 
     <Setter Property="TextWrapping" Value="Wrap"/> 
     <Setter Property="Height" Value="32"/> 
     <Setter Property="Width" Value="170"/> 
     <Setter Property="TextTrimming" Value="WordEllipsis"/> 
     <Setter Property="Margin" Value="10,0,0,0"/> 
    </Style> 

    <Style x:Key="PostedText" TargetType="TextBlock"> 
     <Setter Property="FontSize" Value="12"/> 
     <Setter Property="TextWrapping" Value="Wrap"/> 
     <Setter Property="Height" Value="14"/> 
     <Setter Property="Width" Value="230"/> 
     <Setter Property="Margin" Value="0,10,0,0"/> 
    </Style> 

    <Style x:Key="AuthorText" TargetType="TextBlock"> 
     <Setter Property="FontSize" Value="12"/> 
     <Setter Property="TextWrapping" Value="Wrap"/> 
     <Setter Property="Height" Value="14"/> 
     <Setter Property="Width" Value="230"/> 
    </Style> 

    <Style x:Key="ContentText" TargetType="TextBlock"> 
     <Setter Property="LineStackingStrategy" Value="BlockLineHeight"/> 
     <Setter Property="FontSize" Value="12"/> 
     <Setter Property="TextWrapping" Value="Wrap"/> 
     <Setter Property="MaxHeight" Value="90"/> 
     <Setter Property="Width" Value="230"/> 
     <Setter Property="TextTrimming" Value="WordEllipsis"/> 
    </Style> 

    <Style x:Key="ReadMoreText" TargetType="TextBlock"> 
     <Setter Property="FontSize" Value="12"/> 
     <Setter Property="Height" Value="16"/> 
    </Style> 

    <Style x:Key="HLBStyling" TargetType="HyperlinkButton"> 
     <Setter Property="BorderThickness" Value="0"/> 
     <Setter Property="IsTabStop" Value="False"/> 
    </Style> 
+0

不是這個bug:http://peterbrady.net/News/Details/quick-fix-for-silverlight-hyperlinkbutton-rendering – 2012-03-12 20:00:14

+0

你的xaml是什麼樣的?我無法重現該問題與 2012-03-12 20:21:20

+0

我增加了XAML。我在你的代碼和我的代碼之間唯一真正的區別是Grid vs Canvas。 – 2012-03-12 20:25:51

回答

0

這是由你的這兩種風格您正在使用HyperLinkBut​​ton(HLBStyling)和它們所包含的造成的TextBlocks(AuthorText,ReadMoreText) 。 如果刪除了TextBlock並只設置了HyperLinkBut​​ton的內容,問題就消失了。此外,如果您從按鈕中的TextBlocks刪除樣式,問題就會消失。

+0

你知道是什麼造成的嗎?除了「你的風格」。這更多的是解決問題。 – 2012-03-13 15:57:40

+0

我非常感謝你的幫助,我只是在尋找比這更深的答案。 – 2012-03-13 15:58:56

+0

這是由TextBlock樣式的Height屬性引起的。您將高度設置爲14,但當您將鼠標移過 – 2012-03-13 18:06:48

相關問題