1

我目前正在尝试向我的超链接按钮添加一些样式,但无法使其正常工作。

经过一番搜索,我找到了这个教程,但即使复制了整个代码(并且只更改了图片),它对我也不起作用。我的 SDK 目标是 7.5。

这是我的代码:

   <ScrollViewer>
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <HyperlinkButton NavigateUri="/Views/PanoramaPage.xaml" Content="Panorama" Foreground="{StaticResource PhoneAccentBrush}"/>
            <HyperlinkButton NavigateUri="/Views/PanoramaPage.xaml" Content="Pivot" Foreground="{StaticResource PhoneAccentBrush}"/>

            <HyperlinkButton Name="hyperlinkButton1" NavigateUri="/Views/PanoramaPage.xaml" >
                <Border BorderBrush="White" BorderThickness="5" Padding="10">
                    <StackPanel Orientation="Horizontal">
                        <Image Width="60" Source="/Presentation;component/Images/refresh.png" />
                        <TextBlock VerticalAlignment="Center" Text="Go to View.xaml"/>
                    </StackPanel>
                </Border>
            </HyperlinkButton>

        </StackPanel>
    </ScrollViewer>

教程网址: http ://www.imaginativeuniversal.com/blog/post/2010/07/05/Navigating-around-windows-phone-7.aspx

4

1 回答 1

7

HyperlinkBut​​ton 的默认控件模板是 TextBlock,因此它只能处理文本!

解决此问题的一种方法是更改​​控件模板,如下所示:

<HyperlinkButton Name="hyperlinkButton1" NavigateUri="/Views/PanoramaPage.xaml">
    <HyperlinkButton.Template>
        <ControlTemplate TargetType="HyperlinkButton">
            <Border BorderBrush="White" BorderThickness="5" Padding="10">
                <StackPanel Orientation="Horizontal">
                    <Image Width="60" Source="/Presentation;component/Images/refresh.png" />
                    <TextBlock VerticalAlignment="Center" Text="Go to View.xaml"/>
                </StackPanel>
            </Border>
        </ControlTemplate>
    </HyperlinkButton.Template>
</HyperlinkButton>
于 2012-04-20T13:14:27.457 回答