我无法在 WP 8.1 的 CommandBar 中为 AppBarButton 应用自定义样式

I cannot apply a custom style for an AppBarButton inside a CommandBar in WP 8.1

我有一个非常具体的问题。我找不到这个确切问题的任何答案,所以我使用反复试验的方法来查明问题所在。这是我遇到问题的示例代码:

<Page.BottomAppBar>
    <CommandBar x:Name="MainMenuCommandBar" ClosedDisplayMode="Minimal">
        <CommandBar.PrimaryCommands>
            <AppBarButton x:Name="otherCommandButton" Label="Egyéb" Icon="List" Click="otherCommandButton_Click" Style="{StaticResource appbarButton}">
                <AppBarButton.Flyout>
                    <MenuFlyout>
                        <MenuFlyoutItem x:Name="SecondaryFlyout1" Text="Névjegy" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                        <MenuFlyoutItem x:Name="SecondaryFlyout2" Text="Adatbázis mentés" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                        <MenuFlyoutItem x:Name="SecondaryFlyout3" Text="Adatbázis visszaállítás" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                        <MenuFlyoutItem x:Name="SecondaryFlyout4" Text="Terminál törlése" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                        <MenuFlyoutItem x:Name="SecondaryFlyout5" Text="Jelszavas védelem" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                        <MenuFlyoutItem x:Name="SecondaryFlyout6" Text="Nyelv váltás" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                        <MenuFlyoutItem x:Name="SecondaryFlyout7" Text="Betűméret" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                        <MenuFlyoutItem x:Name="SecondaryFlyout8" Text="Kilépés" Style="{StaticResource BottomAppBarFlyoutStyle}"/>
                    </MenuFlyout>
                </AppBarButton.Flyout>
            </AppBarButton>
            <AppBarButton x:Name="refreshCommandButton" Label="Frissítés(Bank)" Icon="Refresh" Style="{StaticResource appbarButton}"/>
            <AppBarButton x:Name="syncCommandButton" Label="Szinkronizál(PC)" Icon="Sync" Style="{StaticResource appbarButton}"/>
        </CommandBar.PrimaryCommands>
    </CommandBar>
</Page.BottomAppBar>

我想为 commandbar 中的 appbarbuttons 应用自定义样式,因为 Labels 中的文本太长,我看不到整个文本。所以我想,我会让文本变小,或者让 appbarbutton 变宽。设计者向我展示了变化,但是当我 运行 程序时,没有任何变化。 appbarbuttons 使用默认样式,无论我做什么。所以当我 运行 程序时文本不会变小。

在此之后,我试图找出问题所在。我也尝试编辑模板,但是 "edit a copy" 命令是灰色的。我觉得这很奇怪,因为我浏览了 MSDN,在那里我看到 appbarbuttons 实际上有一个我可以编辑的样式。我复制了默认样式,进行了更改,将其作为自定义样式应用到我的 app.xaml 中,但遇到了与以前相同的问题。无论我在风格上做了什么改变,都没有改变。在所有这些失败之后,我在命令栏外放置了一个 appbarbutton。在这种情况下,一切正常。我可以编辑模板的副本,更改会在我 运行 程序时反映出来。另一个奇怪的情况是,menuflyoutitems 可以在命令栏内设置样式。

抱歉冗长的解释,我想介绍一下我已经知道的。简而言之,我的问题是,有什么方法可以在命令栏中设置 appbarbutton 的样式吗?或者,如果没有,是否有其他方法可以创建自定义命令栏?

WindowsPhone 上的 CommandBar 是系统 UI,除了设置它的前景色和背景颜色外,无法由应用自定义。

如果您想自定义各个按钮,您需要为它们实现自己的面板,而不是使用应用栏。您可以在页面底部放置一个水平堆栈面板,并在其中包含自定义的 AppBarButtons。如果你想让它穿鞋并隐藏,你需要设置你自己的逻辑来检测触发输入,然后应用动画来打开和关闭它。