I have a test page inherited from ContentView in Xamarin Forms.
I want to use it in IOS . But I have a conversion promlem (Can Not Convert from ContentView to UIView)
My test page is below.
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class=".....TestPage">
<ContentView.Content>
<StackLayout>
<Label x:Name="TestLabel"
Text="TEST PAGE OPENING"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentView.Content>
</ContentView>
My IOS Function is below.
public override void ViewDidLoad()
{
TestPage page = new TestPage();
View.AddSubview(page);
base.ViewDidLoad();
}
Looking for your helps.
Thanks!
Related
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
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 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.
I am trying to make an app, using Xamarin Forms, in Visual Studio 2015. I want to add background image to the screen/page. So far, I have reached here, as seen in the below code but it doesn't work.
This is my MainPage.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:TrackMyMeds"
x:Class="TrackMyMeds.MainPage"
BackgroundImage="/Images/blue_gradient">
<StackLayout BackgroundColor="Gray" Padding="8,15,8,0">
<Label HorizontalTextAlignment="Center" Text="Welcome to TrackMyMeds" TextColor="White" FontSize="40" FontAttributes="Bold">
</Label>
<Label HorizontalTextAlignment="Center" Text="Let us take charge of your health" TextColor="Black" FontSize="18">
</Label>
<StackLayout Padding="0,40,0,15">
<Label Text="If you already have an account:" TextColor="Black">
</Label>
<Button Clicked="LoginPage_Clicked" Text="Log In Here!" BackgroundColor="#387ef5" TextColor="White" FontSize="18">
</Button>
</StackLayout>
<StackLayout Padding="0,15,0,0">
<Label Text="If you're new here then:" TextColor="Black">
</Label>
<Button Clicked="SignupPage_Clicked" Text="Sign Up Here!" BackgroundColor="#387ef5" TextColor="White" FontSize="18">
</Button>
</StackLayout>
</StackLayout>
</ContentPage>
This is my MainPage.xaml.cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace TrackMyMeds
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void LoginPage_Clicked(object sender, EventArgs e)
{
App.Current.MainPage = new LoginPage();
}
private void SignupPage_Clicked(object sender, EventArgs e)
{
App.Current.MainPage = new SignupPage();
}
}
}
You need to add the image file name to MainPage.xaml file as following:
<?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:BgImgTestApp"
x:Class="BgImgTestApp.MainPage"
BackgroundImage="mobilebg.png">
<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</ContentPage>
Add your image file to respective folders.
For Android: Resources --> Drawable folder,
For iOS: Resources folder,
For Windows & Windows Phone: Assets folder.
You need to do these three changes in MainPage.xaml file for setting Background for Windows Desktop App and Windows Phone App.
1.Remove "Form: WindowsPage", switch to "Page".
2.Add Image Source
MainPage.xaml
<Page
x:Class="BgImgTestApp.Windows.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:forms="using:Xamarin.Forms.Platform.WinRT"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BgImgTestApp.Windows"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Image Source="Assets/mobilebg.png"/>
</Grid>
</Page>
3.comment this:
MainPage.xaml.cs
//LoadApplication(new .....App());
Find the working sample app here: https://github.com/abhiguptame/xamarinsamples/tree/master/BgImgTestApp
Note: You may put resized images according to your device and platform.
If you're viewing on Android you need to keep the file in the the drawable folder of the android project then simply
<ContentPage BackgroundImage = "image.jpg">... </ContentPage>
Got it Right, Just reduced image size and dragged and dropped to the specific folders in Android-->Resources-->drawable directory and iOS resources directory.
Thanks anyways.
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.