AppBar shows half of content

2019-09-18 16:38发布

问题:

I use AppBar for my application and AppBarButtons.

But ABB shows only half of title text and rest after opening AB. I want to hide the text completely and show it only in case of opening AB.

Problem image

<Page.Resources>
    <Style TargetType="AppBarButton" x:Name="appBar">
        <Setter Property="VerticalAlignment" Value="Top"/>
        <Setter Property="HorizontalAlignment" Value="Right"/>
    </Style>
</Page.Resources>

<Page.BottomAppBar>
    <AppBar IsSticky="True" ClosedDisplayMode="Compact" Background="LightGray" >

        <StackPanel Orientation="Horizontal" VerticalAlignment="Top" FlowDirection="RightToLeft" >
            <AppBarButton x:Name="mapaStackPanel" Label="Mapa" Icon="Map" Click="MapaStackPanelClick" Style="{StaticResource appBar}" Visibility="Collapsed" />
            <AppBarButton x:Name="mojePolohaStackPanel"  Label="Moje poloha" Icon="Map" Click="MojePolohaClick" Style="{StaticResource appBar}"/>
            <AppBarButton x:Name="najdiNejblizsiStackPanel"  Label="Najdi Nejbližší" Icon="Map" Click="NajdiNejblizsiClick" Style="{StaticResource appBar}"/>
            <AppBarButton x:Name="navigujStackPanel" Label="Naviguj" Icon="Directions" Click="navigujStackPanel_Click" Visibility="Collapsed" Style="{StaticResource appBar}"/>
        </StackPanel>
    </AppBar>
</Page.BottomAppBar>

Thank you, VT

回答1:

Use a CommandBar instead of the AppBar, due it is designed to provide a layout for AppBarButton and related command elements.

<Page.BottomAppBar>
    <CommandBar IsSticky="True" ClosedDisplayMode="Compact" Background="LightGray" >
        <AppBarButton x:Name="mapaStackPanel" Label="Mapa" Icon="Map" Click="MapaStackPanelClick" Style="{StaticResource appBar}" Visibility="Collapsed" />
        <AppBarButton x:Name="mojePolohaStackPanel"  Label="Moje poloha" Icon="Map" Click="MojePolohaClick" Style="{StaticResource appBar}"/>
        <AppBarButton x:Name="najdiNejblizsiStackPanel"  Label="Najdi Nejbližší" Icon="Map" Click="NajdiNejblizsiClick" Style="{StaticResource appBar}"/>
        <AppBarButton x:Name="navigujStackPanel" Label="Naviguj" Icon="Directions" Click="navigujStackPanel_Click" Visibility="Collapsed" Style="{StaticResource appBar}"/>
    </CommandBar>
</Page.BottomAppBar>