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
Related
the font.otf is imported correctly and placed inside the correct folder because the font works on letters but importing an icon from the otf file does not work because of the syntax error. Entering &#x before the icon code "uf1ea" is what caused the error but it's important for finding the icon otherwise it would just display "uf1ea" on the emulator and not the actual icon.
here's a snippet of the code i wrote in app.xaml :
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="testingfont.App">
<Application.Resources>
<ResourceDictionary>
<x:String x:Key="Newspaper">&#xuf1ea;</x:String>
</ResourceDictionary>
</Application.Resources>
</Application>
You don't need to add a u in your icon code, just use it like below:
<x:String x:Key="Newspaper"></x:String>
After adding the icon codes in a new class, this worked for me:
<Label Text=""/>
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.
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.
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.
I am referencing a library with a different assembly in a Xamarin.Forms app using Xaml in Visual Studio Mac Preview.
<?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:RTE.Test.Forms"
xmlns:rte="clr-namespace:RichTextEditor;assembly=RichTextEditor"
x:Class ="RTE.Test.Forms.RTE_Test_FormsPage">
<rte:RichTextForm
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</ContentPage>
When I look at the iOS preview screen in VS, the RichTextForm renders perfectly. However, when I run the test on iOS simulator, I get the following error:
Xamarin.Forms.Xaml.XamlParseException: Position 8:3. Type rte:RichTextForm not found in xmlns clr-namespace:RichTextEditor;assembly=RichTextEditor
I have tried changing namespaces and assembly names, but since the Previewer can find the type just fine, I don't think this is the problem.