How Xamarin Form Remove Layout Padding with children? - xamarin.forms

I'm beginner in Xamarin Form. This's my xaml code:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BluePin"
x:Class="BluePin.MainPage"
x:Name="MainContentPage">
<RelativeLayout>
<Image Source="BG.png"
Aspect="AspectFill"></Image>
</RelativeLayout>
</ContentPage>
enter image description here
I tested all xamarin layout and controls. Please see picture, there is red distance between layout and control (Image). how can i remove this distances and set image as full screen?

set image as full screen
there are two methods to implement this:
1.set the image as the ContentPage's background
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BluePin"
x:Class="BluePin.MainPage"
x:Name="MainContentPage"
BackgroundImage="BG.png"
>
</ContentPage>
2.use StackLayout:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BluePin"
x:Class="BluePin.MainPage"
x:Name="MainContentPage">
<StackLayout>
<Image Source="BG.png"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Aspect="Fill" />
</StackLayout>
</ContentPage>

Try this:
<ContentPage.Content>
<RelativeLayout>
<Image Aspect="AspectFill" Source="BG.png"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=1}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=1}"/>
</RelativeLayout>
</ContentPage.Content>

If you want to just show the image on the whole screen there is no need for you to define a parent layout secondly its a BAD performance practice to do so :
What your ContentPage XAML should look like:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="Black" x:Name="MainContentPage"
x:Class="BluePin.MainPage">
<ContentPage.Content>
<Image Source="{Binding SelectedImage}" Aspect="AspectFill"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="Transparent" />
</ContentPage.Content>
</ContentPage>

Related

Xamarin Forms - Navigate to child of Tabbed Page

I have a TabbedPage with 3 tabs, where I want to navigate directly to the 2nd content page (TagsListPage), but still keep my Tabbed header.
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
x:Class="BradyRfidDemo.V1.MobileApp.Views.TabbedInventoryPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BradyRfidDemo.V1.MobileApp.Views"
Title=" SCAN PAGE"
Shell.NavBarIsVisible="false">
<local:InventoryPage />
<local:TagsListPage />
<local:Transfer />
</TabbedPage>
TagsListPage: (I removed most of the code to make it clean).
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="BradyRfidDemo.V1.MobileApp.Views.TagList"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="TAGLIST"
BackgroundColor="{StaticResource Color1}">
<ContentPage.Content>
<StackLayout >
<Frame >
<StackLayout
HorizontalOptions="Center"
Orientation="Horizontal"
VerticalOptions="Center">
<Label
x:Name="TagList"
Margin="0,10,0,0"
HorizontalTextAlignment="Center"
Text="TAGLIST" />
</StackLayout>
</Frame>
</StackLayout>
</ContentPage.Content>
</ContentPage>
So I want to access from another form content page, directly the TagsListPage, and keep my tabbed header.
If I go to the main page, I get my tabbed header, but it goes to the first page (InventoryPage)
Navigation.PushAsync(new TabbedInventoryPage());
If I go directly to the TagListPage, then I get my page, but not the tabbed structure which I need as well.
Navigation.PushAsync(new TagsListPage());
I tried a lot of different things, but nothing worked so far, and this looks like a very simple thing to do. Any help is greatly appreciated.

How can I add a frame as a toolbar item in toolbar xamarin forms

Image:
I would like to add a frame to toolbar in Xamarin forms. But toolbar is not accepting.
You cannot add a frame as a Toolbar Item.
You can use, for example the TitleView and customize the whole NavigationView yourself.
For example:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TitleViewSample"
x:Class="TitleViewSample.MainPage">
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal">
<Label Text="Hello World" HorizontalOptions="Center"/>
<Frame BackgroundColor="Yellow" HorizontalOptions="End"/>
</StackLayout>
</NavigationPage.TitleView>
</ContentPage>

xamarin.forms add switch in toolbar

Is it possible to add a switch on the toolbar?
<ContentPage.ToolbarItems>
<ToolbarItem>
<Switch x:Name="Switch1" IsToggled="True" Margin="5,0,0,0"/>
</ToolbarItem>
</ContentPage.ToolbarItems>
Does anybody have any ideas?
Thanks!
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TitleViewSample"
x:Class="TitleViewSample.MainPage">
<NavigationPage.TitleView>
<Switch x:Name="Switch1" IsToggled="True" Margin="5,0,0,0"/>
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
I don't think it is possible. You can, however, take the same approach I did when I needed to customise my title bar.
First, you hide the navigation bar, then you can specify your bar at the top, and use the controls you would like.

XFGloss: How to define as global style in App.xaml

I want to each content page contain the following element
<xfg:ContentPageGloss.BackgroundGradient>
<xfg:Gradient Rotation="170">
<xfg:GradientStep StepColor="#9DCC5F" StepPercentage="0" />
<xfg:GradientStep StepColor="#00B0CD" StepPercentage="1" />
</xfg:Gradient>
</xfg:ContentPageGloss.BackgroundGradient>
How can I do?
Why not create an overload of the ContentPage?
Create a file, for instance, GlossContentPage.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xfg="clr-namespace:XFGloss;assembly=XFGloss"
x:Class="YourApp.Pages.GlossContentPage">
<xfg:ContentPageGloss.BackgroundGradient>
<xfg:Gradient Rotation="170">
<xfg:GradientStep StepColor="#9DCC5F" StepPercentage="0" />
<xfg:GradientStep StepColor="#00B0CD" StepPercentage="1" />
</xfg:Gradient>
</xfg:ContentPageGloss.BackgroundGradient>
</ContentPage>
Now just start using your new GlossContentPage, instead of a regular ContentPage, like:
<pages:GlossContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:YourApp.Pages;assembly=YourApp"
x:Class="YourApp.Pages.MyNewShinyPage">
<Label Text="Welcome to Xamarin.Forms" HorizontalOptions="Center" VerticalOptions="Center" />
</pages:GlossContentPage>

Sequence contains no elements XAML ContentPage

In line 1, my axml file reports the error Sequence contains no elements ...
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:my_namespace"
x:Class="my_class_name"
Title="Login"
NavigationPage.HasNavigationBar="false">
<ContentPage.Content>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Center">
<ContentView Padding="0,40,0,40" VerticalOptions="FillAndExpand">
<Image Source="xamarin_logo.png" VerticalOptions="Center" HeightRequest="64" />
</ContentView>
</StackLayout>
<StackLayout Spacing="10" Padding="20" VerticalOptions="Center">
<Entry x:Name="companyNameEntry" Placeholder="Nome Società" Text="TERMINALINI" />
<Entry x:Name="usernameEntry" Placeholder="ID Utente" Text="manager" />
<Entry x:Name="passwordEntry" Placeholder="Password" IsPassword="true" Text="XXX" />
<Button Text="Login" TextColor="White" BackgroundColor="#77D065" Clicked="OnLoginButtonClicked" />
<Label x:Name="messageLabel" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
I tried what the error meant but I do not understand it ... what did I do wrong?
A ContentPage's Content property can only contain a single child. You have two StackLayouts as direct children of Content. They need to be enclosed in a single layout container.

Resources