Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Label not Visible inside Frame in Xamarin Forms?

I'm trying to create simple black border for a label in Xamarin forms. It seems anything inside a frame is not visible.

Here is my code:

<Frame BorderColor="Black"   
       CornerRadius="0">
    <Label x:Name="txtText"
           Text="Here"
               TextColor="Black"
               BackgroundColor="White"
               HorizontalOptions="FillAndExpand"
               VerticalOptions="FillAndExpand"
               HorizontalTextAlignment="Center" />
</Frame>

I can set the background property in my frame to anything and that works OK, I even tried setting it to transparent with no success.

This is what I see with the code above.

enter image description here

I'm using Visual Studio 2017 and Android if that helps.

UPDATE

I've found a solution, but it seems hacky. I've put it all inside a StackLayout, set the request height of the frame to 100 and set the padding to 1.

Here is the updated code:

<StackLayout>
    <Frame BorderColor="{DynamicResource PrimaryColour}"   
           CornerRadius="0"
           Padding="1"
           HeightRequest="100">
        <Label x:Name="txtText"
               Text="Here"
               TextColor="{DynamicResource PrimaryColour}"
               BackgroundColor="{DynamicResource SecondaryColour}"
               HorizontalTextAlignment="Center"
               VerticalTextAlignment="Center"/>
    </Frame>
</StackLayout>
like image 293
Noobie3001 Avatar asked Aug 06 '18 22:08

Noobie3001


People also ask

What is frame in Xamarin?

The Xamarin. Forms Frame class is a layout used to wrap a view with a border that can be configured with color, shadow, and other options. Frames are commonly used to create borders around controls but can be used to create more complex UI.


1 Answers

Frame takes some default padding of 20 ,so if frame is really small then elements inside it will never show. So,just make padding="0".

like image 95
bhavya joshi Avatar answered Sep 17 '22 08:09

bhavya joshi