Content of child page doesn't show in tabbedpage (Xamarin Forms) - c#

I'm new to Xamarin and XAML so i downloaded a sample solution which has 3 tabbed pages and each of them contains a child page. Each child page has a label with different text on it. I managed to write a program that is supposed to do the same thing, but the label doesn't show on any of the child pages. I can change the background color and title on the child pages.
Here's the code for the MainPage (TabPage):
<?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:pages="clr-namespace:MozaikMuzeum_Xamarin.View;assembly=MozaikMuzeum_Xamarin"
x:Class="MozaikMuzeum_Xamarin.View.TabPage">
<TabbedPage.Children>
<pages:ActualPage />
<pages:CatalogPage />
<pages:BadgesPage />
</TabbedPage.Children>
</TabbedPage>
And here's the code for one of the child pages:
<?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="MozaikMuzeum_Xamarin.View.ActualPage" Title="Aktuális" BackgroundColor="Green">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<ContentPage.Content>
<Label Text="Hi there from Page 1" TextColor="White" Font="20"
VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage.Content>
</ContentPage>
As you can see the label doesn't show between the ContantPage.Content tags.

Related

How to remove Actionbar In MAUI

My XAML Code for view
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="White"
Title=""
x:Class="Chuxi.MainPage">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
</VerticalStackLayout>
</ScrollView>
I have Tried C# Code TO Remove BUt Doesnt Working
public MainPage()
{
NavigationPage.SetHasNavigationBar(this, false);
InitializeComponent();
}
How Can I Remove Title Bar And Make It Full Screen View
This May Help You. Its working For me
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage NavigationPage.HasNavigationBar="false"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="White"
Title=""
x:Class="Chuxi.MainPage">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Any Issue ask me on comment. Thank You

There is a way to show some content in a Xamarin Page XAML based on a variable?

I'm trying to write a page that must show some content based on a variable in the binded class.
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"
x:Class="MyProject.MyClass"
Title="Beautiful Title">
<ContentPage.Content>
//If something true in the MyClass.cs
<StackLayout>
<Label Text="Yeeee" />
<ListView>
...
</ListView>
</StackLayout>
//Else
<AbsoluteLayout>
<Label Text="Noooo" />
<Button>
...
</Button>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
There is a way to do that? My goal is to write a single page instead of two page that differs for few lines of code.

How can I set different Title Views for different pages in TabbedPage layout in Xamarin.Forms?

I have a main Navigation Page that is a Tabbed Page, linking different views.
I've set the in the main Tabbed Page and it works, but I would like to set it different for each page.
This is the Tabbed Page:
<TabbedPage
NavigationPage.HasBackButton="False"
BackgroundColor="Black"
xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestProiectLicenta.Views.UserPageForm" xmlns:local="clr-namespace:TestProiectLicenta.Views"
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
xmlns:refresh="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh">
<TabbedPage.Children>
<local:CarsListPage Title="Cars" Icon="new_car_icon"/>
<local:NewCarsListPage Title="New Cars" Icon="new_car_icon"/>
<local:ChooseMethodFormPage Title="Add Car" Icon="new_add_icon" />
<local:UserViewPage Title="New Page Test" Icon="new_user_icon" />
<ContentPage Title="Settings" Icon="new_settings_icon.png">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Horizontal">
<Image Source="face_id" />
<Label Text="FaceID Login?" />
</StackLayout>
<Switch IsToggled="false" Toggled="Handle_Toggled" x:Name="Fid" />
</StackLayout>
<Button Text="Sign Out" Clicked="SignOutButton" />
</StackLayout>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>
The views are Content Pages.
I would like to have a Title View for the first page with some controls, like search, delete etc. (it's a list of cars) and the user's picture, and the others with the title and maybe other controls.
Usually what I do is I set the Title property in every ContentPage and it reflects on to the page when I flip through tabs
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.BackButtonTitle=""
Title="My Demo Title">...
Update:
In your TabbedPage, you can add the NavigationPage's TitleView something like below
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.BackButtonTitle=""
Title="My Demo Title">
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal">
<Image x:Name="TitleImage"/>
<Label x:Name="TitleLabel"/>
</StackLayout>
</NavigationPage.TitleView>
Hope you can take care of the alignment and everything else.
So Now using the above names you will be able to access the title image and label whenever you please!!
I have found a solution to my problem. Inside the TabbedPage, for each page that you need to have a special Navigation Bar you declare it like this:
<NavigationPage Title="Schedule" IconImageSource="schedule.png">
<x:Arguments>
<local:SchedulePage />
</x:Arguments>
</NavigationPage>
Then you edit the new page and add the
<NavigationPage.TitleView/>

Xamarin Master and MasterDetailPage InvalidOperationException

I am not sure why I am getting this error I have read alot about this error and sounds like it is related to the title in the xaml file not being set. All my pages have the title set. The error is coming from the app.xaml.cs MainPage= new MainPage();
is there something else that can trigger this exeception?
System.InvalidOperationException: Master and Detail must be set before adding MasterDetailPage to a container
MainPage.xaml
<?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:pages="clr-namespace:ReimbursementApp.Pages"
x:Class="ReimbursementApp.Pages.MainPage"
xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
Title="Main">
<MasterDetailPage.Master>
<pages:MenuPage />
</MasterDetailPage.Master>
</MasterDetailPage>
MenuPage.xaml
<?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="ReimbursementApp.Pages.MenuPage"
xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
xmlns:telerik="clr-namespace:Telerik.XamarinForms.DataControls;assembly=Telerik.XamarinForms.DataControls"
Title="Menu">
<!--<ContentPage.ToolbarItems>
<ToolbarItem Activated="OnToolbarButtonClick" Order="Primary" Priority="0" Icon="hamburgerButtonIcon"/>
</ContentPage.ToolbarItems>
<Grid>
<telerikPrimitives:RadSideDrawer x:Name="drawer" DrawerLength="250">
</telerikPrimitives:RadSideDrawer>
</Grid>-->
<StackLayout VerticalOptions="FillAndExpand">
<ListView x:Name="ListViewMenu"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Label Text="{Binding Title}" FontSize="20"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
The error message is literally saying what's wrong:
Master and Detail must be set before adding MasterDetailPage to a container
You already have set something in the Master property, like this:
<MasterDetailPage.Master>
<pages:MenuPage />
</MasterDetailPage.Master>
But you should also set the Detail property, something like this:
<MasterDetailPage.Detail>
<pages:MyMainPage />
</MasterDetailPage.Detail>
The MasterDetailPage is only a container and must have both a master (usually a menu) and a detail (something picked from the menu) to show something useful.
I have also seen this error occur if the page designated as the MasterDetailPage does not load correctly i.e. there may be errors in your xaml on that page or even errors found loading a static resource specified in your App.xaml. This was the case for me and fixing the errors resolved my problem.

Xamarin base ContentPage with loading (or common ContentViews)

how can I create a "base" ContentPage that contains, for sample, a busy indicator, and make this Page the base for each other pages inside my application?
I have tried to do in this way, but the busy indicator isn't showed.
Base 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"
xmlns:core="clr-namespace:SgatMobileV3.Core;assembly=SgatMobileV3"
x:Class="SgatMobileV3.Core.BasePage">
<ContentPage.Content>
<Grid>
<core:VolosLoadingView />
</Grid>
</ContentPage.Content>
</ContentPage>
Busy indicator view:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:core="clr-namespace:SgatMobileV3.Core;assembly=SgatMobileV3"
core:LocatorViewModel.AutoWireViewModel="true"
x:Class="SgatMobileV3.Core.VolosLoadingView"
xmlns:busyindicator="clr-namespace:Syncfusion.SfBusyIndicator.XForms;assembly=Syncfusion.SfBusyIndicator.XForms">
<Grid>
<Grid BackgroundColor="LightGray" Opacity="0.6" IsVisible="True" />
<busyindicator:SfBusyIndicator
IsBusy="True"
IsVisible="True"
x:Name="loading" AnimationType="DoubleCircle"
ViewBoxWidth="150" ViewBoxHeight="150"
TextColor="Green" BackgroundColor="Transparent"
HorizontalOptions="Center" VerticalOptions="Center"/>
</Grid>
</ContentView>
A page:
<core:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:core="clr-namespace:SgatMobileV3.Core;assembly=SgatMobileV3"
core:LocatorViewModel.AutoWireViewModel="true"
x:Class="SgatMobileV3.Views.MockPage">
<ContentPage.Content>
<Grid>
<Button Text="Welcome to Xamarin.Forms! 1"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
Command="{Binding Test_ClickCommand}" />
</Grid>
</ContentPage.Content>
</core:BasePage>
I have tried to include a sample label inside the base page but nothing appears.
how can I create a "base" ContentPage that contains, for sample, a busy indicator, and make this Page the base for each other pages
If want Creating a ControlTemplate at Page Level,creating ControlTemplate instances at the application level, they can also be created at the page level, as shown in the following code example:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SimpleTheme.HomePage">
<ContentPage.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="TealTemplate">
...
</ControlTemplate>
<ControlTemplate x:Key="AquaTemplate">
...
</ControlTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<ContentView ... ControlTemplate="{StaticResource TealTemplate}">
...
</ContentView>
</ContentPage>
When adding a ControlTemplate at the page level, a ResourceDictionary is added to the ContentPage, and then theControlTemplate` instances are included in the ResourceDictionary.
And also can use code , from doc has a sample for example.
You can do that adding the control in the code (in BasePage.cs file), I don't think there is XAML solution for that.

Categories