user3821206
user3821206

Reputation: 619

2 different stackpanels in a BottomAppBar Universal App

I am trying to put the elements in my BottomAppBar like that:

enter image description here

with this code I get the two stackpanels in the left,can you correct please my code:

<Page.BottomAppBar>
        <CommandBar Background="#eff0f2">
            <CommandBar.Content>
                <Grid HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch">
                        <Image Source="images/1.png" Height="35" Width="35" />
                        <ComboBox Margin="2" BorderThickness="0" SelectedItem="Français">
                            <ComboBoxItem Content="Français" />
                            <ComboBoxItem Content="Anglais" />
                        </ComboBox>
                        <Button VerticalAlignment="Stretch" Background="#eff0f2" >
                            <Button.Content>
                                <TextBlock Text="Conditions des données" Foreground="#336699"></TextBlock>
                            </Button.Content>
                        </Button>
                        <Button VerticalAlignment="Stretch" Background="#eff0f2" Margin="0">
                            <TextBlock Text="-Mentions légales" Foreground="#336699"></TextBlock>
                        </Button>
                        <Button VerticalAlignment="Stretch" Background="#eff0f2" Margin="0">
                            <TextBlock Text="-Impressum" Foreground="#336699"></TextBlock>
                        </Button>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"  Grid.Row="0" Grid.Column="1" >
                        <Image Source="images/marque.png" Height="35" Width="35"  />
                        <TextBlock Text="2015 OAASE Corporation|All Right Reserved." Foreground="#666666" Margin="10" />
                    </StackPanel>
                </Grid>
            </CommandBar.Content>
        </CommandBar>
    </Page.BottomAppBar>

thanks for help :)

Upvotes: 1

Views: 160

Answers (1)

t.ouvre
t.ouvre

Reputation: 2981

You just have to add Stretch HorizontalContentAlignment to CommandBar :

<CommandBar HorizontalContentAlignment="Stretch">

EDIT: @user3821206, a quick fix for your problem of responsiveness is to set a minimum width to the first column, and set the width of the second column to Auto. When the screen is too small, the right part is cropped :

<Grid.ColumnDefinitions>
    <ColumnDefinition MinWidth="550" Width="*" />
    <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

A better and complementary fix is to use VisualStateManager and AdaptiveTrigger. For example, you can hide the right panel if the screen size is less than 720. To do that, give a name to your right Stackpanel :

<StackPanel x:Name="RightPanel"

And add the following snippet in the first container of your page (for me, it's a Grid) :

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <!-- Start of snippet -->
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup>
            <VisualState>
                <!-- Edit style for small screen -->
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="0" />
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="RightPanel.Visibility"
                            Value="Collapsed" />
                </VisualState.Setters>
            </VisualState>
            <VisualState>
                <!-- Disable previous changes for large screen -->
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="720" />
                </VisualState.StateTriggers>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <!-- End of snippet -->
</Grid>

Upvotes: 2

Related Questions