remove back button page xamarin xaml - xaml

show the page :
await Shell.Current.GoToAsync("HabeasData");
in HabeasData constructor I put the following:
NavigationPage.SetHasBackButton(this, false);
InitializeComponent();
Too i try this:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Habeasdata"
x:Class="AppColantaDomicilios.Views.HabeasData"
NavigationPage.HasBackButton="False" >
But, it does not work, keep showing the back button.
Xamarin.Forms is updated.
I would greatly appreciate the help.

NavigationPage.SetHasBackButton(this, false); is not worked in Shell
You can use Shell.NavBarIsVisible="False" in the ContentPage like following code.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Shell.NavBarIsVisible="False"
x:Class="App7.Views.Page1">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Here is related article about it.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/configuration#disable-the-navigation-bar
If you still want to keep the title bar and hide the back button. you can add a custom navigation bar with your stack layout. Or use following code and add a transparent png like following GIF.
Here is code.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="App7.Views.Page1">
<Shell.BackButtonBehavior>
<BackButtonBehavior IsEnabled="False" IconOverride="test.png"
/>
</Shell.BackButtonBehavior>
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Here is transparent png.

Related

Xamarin.iOS Error - Application windows are expected to have a root view controller .... Using Static Binding

I am getting this error:
Foundation.MonoTouchException: Objective-C exception thrown. Name:
NSInternalInconsistencyException Reason: Application windows are
expected to have a root view controller at the end of application
launch
Using Xamarin.iOS if I use inside my xaml file this kind of Binding:
<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
xmlns:converters="clr-namespace:AppAlgorix.Converters"
xmlns:resources="clr-namespace:AppAlgorix.Resources"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="AppAlgorix.Views.LoginPage">
<ContentPage.Resources>
<ResourceDictionary>
<converters:MaskedCardConverter x:Key="cvtMaskedCard"></converters:MaskedCardConverter>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Orientation="Vertical" HorizontalOptions="Center" Padding="20">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="Fill" HeightRequest="80">
<Label Text="SEJA BEM VINDO" HorizontalOptions="CenterAndExpand" FontSize="Large" FontAttributes="None" TextColor="{Binding Source={x:Static resources:AppParameters.AppLabelColorDefault}}"></Label>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
I have tried this format also:
<Label Text="SEJA BEM VINDO" HorizontalOptions="CenterAndExpand"
FontSize="Large" FontAttributes="None" TextColor="{Binding
AppLabelColorDefault, Source={x:Static
resources:AppParameters}}"></Label>
My Parameters Class is this:
namespace AppAlgorix.Resources
{
public static class AppParameters
{
public static string AppLabelColorDefault
{
get
{
var color = Parameters.ResourceManager.GetString("applabelcolordefault");
return color;
}
}
}
}
My Xamarin project has Android and iOS. This approach works with Android, but do not work with iOS.
If I change my view to this :
<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
xmlns:converters="clr-namespace:AppAlgorix.Converters"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="AppAlgorix.Views.LoginPage">
<ContentPage.Resources>
<ResourceDictionary>
<converters:MaskedCardConverter x:Key="cvtMaskedCard"></converters:MaskedCardConverter>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Orientation="Vertical" HorizontalOptions="Center" Padding="20">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="Fill" HeightRequest="80">
<Label Text="SEJA BEM VINDO" HorizontalOptions="CenterAndExpand" FontSize="Large" FontAttributes="None" TextColor="Black"></Label>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
I can execute and see my view in emulator...
So, I think my problem is this Binding format...
My question is... How to resolve this error in Xamarin.iOS, without breaking Xamarin.Android ?

XAML Page With Grid And Button

I have a grid which will take up most of my Xamarin.Forms Page, and I want to add a button below the grid. My issue is that I am using the below syntax to add the button, however the button fills the entire page.
What do I need to change so that the button appears directly below the grid?
<?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="XF.Pages.AEI" >
<ContentView Content="{Binding ApprovedUserGrid,Mode=TwoWay}" Padding="0,30,0,0"/>
<Button Command="{Binding OkayCommand}" Text="Okay" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"
BackgroundColor="#088da5" />
</ContentPage>
This is C# for my grid (not where I actually bind, but the creation)
private Grid _Grid;
public Grid TestGrid
{
get { return _Grid ?? (_Grid=new Grid()); }
set
{
_Grid = value;
NotifyPropertyChanged();
}
}
EDIT
I edit code to read like this, and there are no errors, but I do not see my button on the page?
<?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="XF_Login.Pages.ApproveUsers" >
<StackLayout Orientation="Vertical" Padding="30" Spacing="40">
<ContentView Content="{Binding ApprovedUserGrid,Mode=TwoWay}" Padding="0,30,0,0"/>
<Button Command="{Binding OkayCommand}" Text="Okay" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"
BackgroundColor="#088da5" />
</StackLayout>
</ContentPage>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XF_Login.Pages.ApproveUsers" >
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" Padding="30" Spacing="40">
<ContentView VerticalOptions="FillAndExpand" Content="{Binding ApprovedUserGrid,Mode=TwoWay}" Padding="0,30,0,0"/>
<Button Command="{Binding OkayCommand}" Text="Okay" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="Center"
BackgroundColor="#088da5" />
</StackLayout>
</ContentPage>

TabbedPage crashes app on start up. Others don't

I encountered this issue tonight and after hours of brainstorming I thought i'd ask. Please refer to the code below:
App.xaml.cs
MainPage = new NavigationPage(new MainPage());
// MainPage = new NavigationPage(new ActivitiesPage());
The above code does not run for some reason. I have done a test with the commented code below and everything functions just how it should. Does anyone know the reason for this? The code for both xaml classes (MainPage and ActivitiesPage) are below.
MainPage
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Instagram_App.View.MainPage"
xmlns:view="clr-namespace:Instagram_App.View;assembly=Instagram_App">
<view:ActivitiesPage Title="Activities" Icon="heart.png"/>
<view:ProfilePage Title="Profile" Icon="user.png"/>
</TabbedPage>
ActivitiesPage
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Instagram_App.View.ActivitiesPage">
<ContentPage.Content>
<ListView x:Name="listView" ItemSelected="ListView_OnItemSelected" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">
<Image Source="{Binding ImageUrl}" />
<Label Text="{Binding Description}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
I have stepped through the code to see what happens and it seems that when the compiler gets to OnStart() it crashes. Please help and thanks!
A TabbedPage should be the root (MainPage) of your App, not contained within a NavigationPage. However, each tab within a TabbedPage can contain a NavigationPage
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TabbedPageWithNavigationPage;assembly=TabbedPageWithNavigationPage"
x:Class="TabbedPageWithNavigationPage.MainPage">
<local:TodayPage />
<NavigationPage Title="Schedule" Icon="schedule.png">
<x:Arguments>
<local:SchedulePage />
</x:Arguments>
</NavigationPage>
</TabbedPage>
According to your code,
your MainPage should be setted as TabbedPage and Root of Your App.
So you could modify App.xaml.cs as follows:
MainPage = new MainPage();
If you want tab Contain NavigationPage to TabbedPage, you can use the Last responder's answer:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TabbedPageWithNavigationPage;assembly=TabbedPageWithNavigationPage"
x:Class="TabbedPageWithNavigationPage.MainPage">
<local:TodayPage />
<NavigationPage Title="Schedule" Icon="schedule.png">
<x:Arguments>
<local:SchedulePage />
</x:Arguments>
</NavigationPage>
And,if have Doubt,you can refer to the official documentation:
[TabbedPage use and demo][1]
[1]: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page

Xamarin MasterDetailPage ContentPropertyAttribute

I'm trying to learn Xamarin and I was doing a simple MasterDetailPage to run on iOS. After running the code I got this error:
Can not set the content of MasterDetailPage as it doesn't have a ContentPropertyAttribute
Below is my XAML file code snippet:
<?xml version="1.0" encoding="utf-8"?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MasterDetailLearing" x:Class="MasterDetailLearing.MainPage">
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
<MasterDetailPage.Master>
<ContentPage Padding="10" BackgroundColor="Gray" Title="Master">
<ContentPage.Content>
<StackLayout Margin="5,30,5,5">
<Label Text="Master Page"></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<ContentPage Padding="10">
<ContentPage.Content>
<StackLayout Margin="5,30,5,5">
<Label Text="Detail Page"></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
a MasterDetail page only has Master and Detail children. You cannot include any other content as a direct child. So your Label needs to be in either the Master or the Detail, it cannot be a direct child of the page.

NavigationPage Wrapping causing bug in status bar

I'm experiencing a weird bug when I try to add Navigation to my CropsListPage
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-Balloney.Views"
x:Class="Balloney.Views.MainPage">
<NavigationPage Icon="carrot.png">
<x:Arguments>
<local:CropListPage/>
</x:Arguments>
</NavigationPage>
<ContentPage Icon="search.png"></ContentPage>
</TabbedPage>
And then it results in..
If I don't try to envelop it in a NavigationPage, it stays normal
Any idea what's causing this behaviour ? Before trying to hammer my way outta this and hardcoding the size of the status bar in Android, I'm looking for a way to understand the problem and prevent it. Thanks
MainPage.xaml working now
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Balloney.Views"
x:Class="Balloney.Views.MainPage">
<local:CropListPage Icon="carrot.png"/>
<ContentPage Icon="search.png"></ContentPage>
</TabbedPage>
And the CropList xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Balloney.Views.CropListPage">
<ListView ItemsSource="{Binding CropsList}" ItemTapped="OnCropTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Image Source="{Binding ImageUrl}" VerticalOptions="Fill" WidthRequest="50"/>
<StackLayout HorizontalOptions="StartAndExpand">
<Label Text="{Binding Specie.Name}"/>
<Label Text="{Binding HarvestDate}" FontSize="Micro" TextColor="Black"/>
</StackLayout>
<Label Text="{Binding Location}" FontSize="Micro" TextColor="Chocolate" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
EDIT: The error seems to be related to the ListView I have inside CropListPage because there's no bug when I switch to the Search icon Page.
The extra space in your first image is the result of the NavigationPage by default showing the Navigation bar, which can be hidden.
Here's an example of how to hide it.
Is may be because you have wrapped crop list page in a navigation page so when that is selected you get the nav bar space above.
If you select the second tab, does the space disappear?
If you add a title to crop page does it appear in the large green space?
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Chronocrops.Views"
x:Class="Chronocrops.Views.MainPage">
<NavigationPage Icon="carrot.png" Title="Crop List">
<x:Arguments>
<local:CropListPage/>
</x:Arguments>
</NavigationPage>
<ContentPage Icon="search.png"></ContentPage>
</TabbedPage>