1

In my app profile page I'm showing some buttons horizontally and it is looking good in iPhone 7 but when it comes to iPhone 5 buttons are not looking great because of small screen size. I want to make the layout of buttons align vertically on small screens. Please see the following sample code.

`

<App Background="#eeef">
  <Fuse.iOS.StatusBarConfig ux:Name="statusBarConfig" Style="Dark"/>
    <StackPanel ux:Name="textPanel" Alignment="Center">
      <Text ux:Class="TitleText" Color="#000" TextAlignment="Center" Padding="2"/>
      <TitleText ux:Name="topText">This is a long text aligned horizontally</TitleText>
      <TitleText ux:Name="bottomText">This is a another long text</TitleText>
    </StackPanel>
</App>

`

These two text are aligned horizontally in all screens. How i can make it automatically align vertically on small screens?

Unnikrishnan
  • 2,683
  • 5
  • 22
  • 39

1 Answers1

2

As we found out, your question is actually about changing the stacking orientation of the StackPanel, not about alignment.

To achieve that, you need to use such triggers as WhileWindowSize and WhileWindowPortrait/WhileWindowLandscape. It is well explained in Responsive layout docs.

Here's an example app that does what you were looking for:

<App>
    <Text ux:Class="TitleText" Color="#000" TextAlignment="Center" Padding="2"/>
    <!-- create a new trigger shorthand for when we are running on a "big screen" -->
    <WhileWindowSize ux:Class="WhileBigScreen" GreaterThan="599,1" />

    <!-- by default (on small screens in portrait), stack things vertically -->
    <StackPanel ux:Name="textPanel" Alignment="Center">
        <TitleText ux:Name="topText">This is a long text aligned horizontally</TitleText>
        <TitleText ux:Name="bottomText">This is a another long text</TitleText>
    </StackPanel>

    <!-- when running on a big screen, stack things horizontally disregarding what the device orientation is -->
    <WhileBigScreen>
        <Change textPanel.Orientation="Horizontal" />
    </WhileBigScreen>
    <!-- when running on a small screen, only stack things horizontally when in landscape -->
    <WhileBigScreen Invert="true">
        <WhileWindowLandscape>
            <Change textPanel.Orientation="Horizontal" />
        </WhileWindowLandscape>
    </WhileBigScreen>
</App>
eksperts
  • 149
  • 4