1

我使用 silverlight 模板创建了一个导航应用程序。我确实有 4 个名为Home, About, Info, MapsNow 的选项卡,当我选择任何人时,它工作正常,但看起来不像选择了哪个选项卡。因为选定的一个选项卡没有颜色变化。

请建议我如何更改所选标签的颜色?

谢谢

4

1 回答 1

0

我自己从来没有明确地玩过这个,但是在默认样式下,这种行为是存在的

            <Border x:Name="LinksBorder" Style="{StaticResource LinksBorderStyle}">
                <StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}">

                    <HyperlinkButton x:Name="Link2" Style="{StaticResource LinkStyle}" 
                                 NavigateUri="/About" TargetName="ContentFrame" Content="About"/>
                </StackPanel>
            </Border>

在后面的代码中:

    // After the Frame navigates, ensure the HyperlinkButton representing the current page is selected
    private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
    {
        //This is to hide/show the leftside menu
        ApplyConfiguration(ApplicationConfiguration.GetConfiguration());

        foreach (UIElement child in LinksStackPanel.Children)
        {
            HyperlinkButton hb = child as HyperlinkButton;
            if (hb != null && hb.NavigateUri != null)
            {
                if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
                {
                    VisualStateManager.GoToState(hb, "ActiveLink", true);
                }
                else
                {
                    VisualStateManager.GoToState(hb, "InactiveLink", true);
                }
            }
        }
    }

注意非活动的转到状态活动。此代码来自一个导航 silverlight 项目的默认模板。保留样式的 StaticResource 应该可以解决问题。然后你可以去创造你自己的风格

于 2012-04-23T17:50:28.097 回答