Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Center view with proportional width only

$
0
0

Hi,
I am making a login page. There is a small view (frame) in the middle that fills 50% of the width, and the height just takes whatever it needs. Is this possible?
In all the ways I know, you either have to set both height and width to a proportional value, and then you can center (using LayoutBounds and LayoutFlags), but I dont want the height to be proportional. I think maybe I could center the frame in a stackview, but I guess then I wont have the proportional width.
I can also use math in code to just move the window, but I preffer keeping it in XAML; there must be a simple way to fix such an easy thing, right?

This is my current code. It is not working properly, because the anchor point of the frame is at 0,0, and not in the middle, so its filling up 50%-100% of the width instead of 25%-75%:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="MariusVipApp.Login">
    <RelativeLayout HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand"
                BackgroundColor="#008aff">

    <Frame CornerRadius="15"
           OutlineColor="DarkGray"
           BackgroundColor="White"
           RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5}"
           RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}"
           RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5}">
        <StackLayout Orientation="Vertical">
            <Label x:Name="labelUsername"
                   FontAttributes="Bold">

            </Label>
            <Entry x:Name="entryUsername"
                   FontAttributes="Bold"
                   HorizontalTextAlignment="Start">

            </Entry>
            <Label x:Name="labelPassword"
                   FontAttributes="Bold">

            </Label>
            <Entry x:Name="entryPassword"
                   HorizontalTextAlignment="Start"
                   FontAttributes="Bold"
                   IsPassword="True">

            </Entry>
        </StackLayout>
    </Frame>
    </RelativeLayout>
</ContentPage>

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>