Can not Add() elements to page (IOS) xaml, gif image - xaml

Hello I'm trying to use FFImageloader package in XAML. I've added the custom renders in appdelegate and mainacticivy on the devices. When it renderes my page it throws an error.
I've tried to remove properties from the new namespace and it still throws this error. I have added the namespaces and installed the following packages from the guide on their github 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="ODEON.Pages.news"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
Title="MainWindow">
<ContentPage.Content>
<ffimageloading:CachedImage HorizontalOptions="Center" VerticalOptions="Center"
WidthRequest="300" HeightRequest="300"
DownsampleToViewSize="true"
Source = "http://loremflickr.com/600/600/nature?filename=simple.jpg">
</ffimageloading:CachedImage>
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding title.rendered}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
this is the error :
ODEON/Pages/news.xaml(10,10): Error: Position 9:10. Can not Add() elements to ODEON.Pages.news.Content (ODEON.iOS)

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 ?

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.

How to use a Frame as the root element of a ListView in Xamarin.Forms?

I am trying to achieve a list of Card-like records for the timeline on an application built in Xamarin.Forms, this is the layout that more or less I need to replicate:
I think I am close, I have two records on my code behind that I assign as the ItemSource to a listView on the XAML side, and this is my result so far:
But as you can see, the elements are not showing at all inside their frame, if I replace the form controls with TextCells or ImageCells, the data shows fine. This is the XAML code I have so far:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage Title="AudioBitts"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AudioBitts"
x:Class="AudioBitts.TimelinePage">
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="300">
<Frame HasShadow="true" Margin="5">
<StackLayout>
<StackLayout Orientation="Horizontal">
<Image Source="{Binding UserAvatar}" />
<Label Text="{Binding UserName}" />
</StackLayout>
<Image Source="{Binding BittImage}" />
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
Am I missing something on the structure I am giving to my XAML code? Thanks!
You can set ListView.RowHeight or set ListView.HasUnevenRow to allow the data to be displayed in full.

Implement Reusable elements in xamarin forms

Iam trying to define reusable components in my xamarin app. My intention is to use same xaml in multiple files. For example, I need to define common header for my app. I tried to implement this in following way : Define required xaml in separate file. Use the class name associated for reusing in any other xaml.
Reusable xaml :
<?xml version="1.0" encoding="utf-8" ?>
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AppHeader" BackgroundColor="White"
Spacing="1"
VerticalOptions="Start">
<StackLayout Padding="0,10,0,10"
BackgroundColor="Blue"
Orientation="Horizontal"
Spacing="0">
<Label
Text="AppName"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
TextColor="White"
></Label>
</StackLayout>
</StackLayout>
Associated Class :
public partial class AppHeader : StackLayout
{
public AppHeader ()
{
InitializeComponent();
}
}
Usage in 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:common="clr-namespace:MyApp;assembly=MyApp"
x:Class="MyApp.SampleView">
<StackLayout>
<common:AppHeader></common:AppHeader>
</StackLayout>
</ContentPage>
While running the app, Im getting following error for reusable xaml file:
"The name 'InitializeComponent' does not exist in the current context"
The implementation look simple, but Im not able to identify what is missing.
Any solution for this?
Any help would be much appreciated.
Thanks
In your StackLayout you have an attribute for your class: x:Class="AppHeader". This should specify the fully qualified class name including the namespace. So edit it to be something like:
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="YouNameSpace.AppHeader" BackgroundColor="White"
Spacing="1"
VerticalOptions="Start">
<StackLayout Padding="0,10,0,10" ...
Remove InitializeComponent(); from your AppHeader constructor. InitializeComponent() is only used by ContentPages.
Also, just noticed the XML you have in your AppHeader XAML. Change that XAML to this (removing all the boilerplate XAML that is only needed in a ContentPage:
<StackLayout BackgroundColor="White"
Spacing="1"
VerticalOptions="Start">
<StackLayout Padding="0,10,0,10"
BackgroundColor="Blue"
Orientation="Horizontal"
Spacing="0">
<Label Text="AppName"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
TextColor="White"></Label>
</StackLayout>
</StackLayout>