在通用应用程序中将鼠标悬停在CommandBar SecondaryCommands上时更改前景色

时间:2016-03-25 13:31:18

标签: winrt-xaml win-universal-app windows-10-universal

我在CommandBar SecondaryCommands中有一个菜单,我列出了样式CommandBar,但我没有找到让我在菜单中的每个项目上悬停时更改前景颜色的行。 这是我的代码:

这是我的CommandBar代码:

<CommandBar Style="{Binding Source={StaticResource commandBarStyle}}" >
            <CommandBar.CommandBarOverflowPresenterStyle>
                <Style TargetType="CommandBarOverflowPresenter">
                    <Setter Property="Background"
                        Value="#00a0e3" ></Setter>
                    <Setter Property="Margin" Value="0"></Setter>
                    <Setter Property="Padding" Value="0"></Setter>
                    <Setter Property="BorderBrush" Value="Transparent"/>
                 </Style>
            </CommandBar.CommandBarOverflowPresenterStyle>

            <CommandBar.SecondaryCommands >
                <AppBarButton Label="Info"
                          Foreground="White" Background="#00a0e3"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

commandBarStyle是Windows应用商店的CommandBar的默认样式,我在&#34; AvailableCommandsStates&#34;中添加了这些行。部分:

 <VisualStateGroup x:Name="AvailableCommandsStates">
                                <VisualState x:Name="BothCommands"/>
                                <VisualState x:Name="PrimaryCommandsOnly">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="OverflowContentRoot" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SecondaryCommandsOnly">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PrimaryItemsControl" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#00a0e3" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#00a0e3" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>

但是当我将鼠标悬停在SecondaryCommands项目上时,总是会得到黑色前景色 再次感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您应该覆盖按钮的样式,而不是栏。您可以在按钮样式中找到PointerOver状态