Today i faced some issue. Please help me.
I created a cross platform application on IOS and Android. So i trying to access my MainPage controls form .cs file but i can't. Here is provided code.
MainPage.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"
xmlns:local="clr-namespace:Movies"
x:Class="Movies.MainPage">
<TableView x:Name="mainTable">
<TableSection>
<ViewCell>
<ViewCell.View>
<Label Text="Hello"></Label>
</ViewCell.View>
</ViewCell>
</TableSection>
</TableView>
</ContentPage>
MainPage.xaml.cs
using Xamarin.Forms;
namespace Movies
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
mainTable.
}
}
}
https://i.imgur.com/OKO3yYc.png
Project runs successfully.
https://i.imgur.com/ondjVkP.png
I tried rebuild and even restore VS17 in VS installer.
this.mainTable doesn't work either.
Click on the .XAML file, select Properties.
See a Property called Custom Tool. Change its value from MSBuild:Compile to MSBuild:UpdateDesignTimeXaml or if it is blank set it to MSBuild:UpdateDesignTimeXaml.
This will solve the problem.
Build the project once,then you can access the name in .cs file.
Related
I am using Shell Tabbed Page, and it's working fine. But when I navigate to a new Page using
Navigation.PushAsync(new SecondPage());
Then inside the Second Page Shell Tabbed also showing, so I need to hide this shell from this page.
How to do this?
From Sheel backend cs page I can hide this,I also try with Messaging Center to hide this but its not working.
In your page just add:
Shell.TabBarIsVisible="False"
Here is a sample:
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.TabBarIsVisible="False"
x:Class="Sample.MySamplePage"
Title="TitleTest">
<StackLayout Spacing="20" Padding="15">
<Label Text="Hello Xamarin"/>
</StackLayout>
</ContentPage>
I am trying to implemenat a TabbedPage with Xamarin Forms. It is very similar to TabbedPage and Content pages are not showing
However I have a quick question as to how to include other xaml files from the MainPage.xam:
Here is my code:
MainPage:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Assignment"
x:Class="Assignment.MainPage">
<TabbedPage.Children>
<local:Alarm /> "The type 'local:Alarm' was not found. Verify that you are not missing..."
</TabbedPage.Children>
The above error is the only build error.
Alarm.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="Assignment.Droid.Resources.layout.Alarm">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Here is my project structure:
On the other link, I saw that he put his xaml files in the layout folder.
Is this the correct setup? I think I have missed something simple.
As Greggz mentions: move it to your shared project.
Then you will have to change your namespaces because that is what actually matters. In .NET land, it is customary that your namespace equals the path on your filesystem.
In you Alarm.xaml, change this line: x:Class="Assignment.Droid.Resources.layout.Alarm" to x:Class="Assignment.Alarm".
Then go into your code-behind, the Alarm.xaml.cs file and change the namespace there too. So change namespace Assignment.Droid.Resources.layout to namespace Assignment.
Since the XAML and the code-behind are implemented as a partial class, this needs to be in sync.
I have a multiplatform app set up, so far it is working decently. My main issue though is I need to change the layout between IOS and Android. In my main solution I have a class called LocationView:
class LocationView : ContentView {
LocationView() {
InitializeView();
}
}
...and it's subsequent 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="Cabs.Views.LocationPage">
<ContentPage.Content>
<Label Text="I'm regular with a bunch of regular stuff" />
</ContentPage.Content>
</ContentPage>
For IOS, I need to change and subsequent controls (UIcontrols based, etc)
What is the correct way of doing this?
I know it has something to do w/ DI, not sure of the syntax. I tried the following:
[assembly: Dependency(typeof(LocationPage))]
It still isn't working
I try calling await Navigation.PushAsync(new DependencyService.Get<LocationPage>())
But I get a compile error
What is the correct procedure for this?
Thanks
I added a third party control in my Xamarin forms project through nuget. I added a xmlns to my xaml for the library, but when I build I get the error: Type flv:FlowListView not found in xmlns clr-namespace:DLToolkit.Forms.Controls.Helpers.FlowListView;assembly=DLToolkit.Forms.Controls.FlowListView
Using the following 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"
xmlns:flv="clr-namespace:DLToolkit.Forms.Controls.Helpers.FlowListView;assembly=DLToolkit.Forms.Controls.FlowListView"
x:Class="FScruiser.XF.Pages.Page1">
<ContentPage.Content>
<flv:FlowListView>
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate>
<ViewCell>
<Label Text="text"/>
</ViewCell>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
</ContentPage.Content>
</ContentPage>
Try this:
clr-namespace:DLToolkit.Forms.Controls
instead of
clr-namespace:DLToolkit.Forms.Controls.Helpers.FlowListView
So, the full namespace definition is this:
xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
Edit: You can also see it in action here on GitHub, in one of the samples.
New to Xamarin so following a simple intro/tutorial (here)to Xamarin forms (using Xamarin Studio on a Mac). Per instructions, I entered the following into the xaml file (HelloXamlPage.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="XamForms.HelloXamlPage"
Title="Hello XAML Page"
Padding="10, 40, 10, 10">
<Label Text="Hello, XAML!"
VerticalOptions="Start"
HorizontalTextAlignment="Center"
Rotation="-15"
IsVisible="true"
FontSize="Large"
FontAttributes="Bold"
TextColor="Aqua" />
</ContentPage>
The code-behind file (HelloXamlPage.xaml.cs) is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace XamForms
{
public partial class HelloXamlPage : ContentPage
{
public HelloXamlPage ()
{
InitializeComponent ();
}
}
}
When I try to build and run it for Android or iOS I get this error: Xamarin.Forms.XamlParseException - No Property of name HorizontalTextAlignment found. Checking the documentation, it's definitely a valid property. Any help/ideas appreciated.
You need to be using one of the latest versions of Xamarin Forms. Upgrade your Xamarin Forms NuGet package to the latest 2.0.1 and you will get the property.
2.0.0 (or the 1.5.2 pre releases) were the first to have the property.
If you use previous xamarin.forms version , You should use 'XAlign' Property Instead. :)