let me start by saying sorry if this is already answered somewhere, I searched for very long time and couldn't find an answer that works.
So as per title, I have a very simple app with literally one page that should display one image from URI and that's it. For some reason the image doesn't show up neither when deploying on a physical device nor on emulator. Image works fine, it's just a random image from web (http://thumbs.dreamstime.com/z/watercolor-autumn-forest-landscape-sunset-hand-drawn-painting-fantasy-art-nature-beautiful-background-gouache-153834924.jpg). I've attached ActivityIndicator that stops spinning after a second, so I would assume that the image is loaded, so it's not an issue with app not connecting to the web and simply image rendering...
I've tried setting Android Options -> Advanced -> HttpClient implementation to Managed and SSL/TLS implementation to Native TLS 1.2+, as well as Android Manifest -> Required Permissions -> Internet. Neither helped. I tried using http:// and https://, no results neither. I'm very confused at the moment.
Here's my App.xaml.cs:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using App1.Services;
using App1.Views;
namespace App1
{
public partial class App : Application
{
public App()
{
InitializeComponent();
DependencyService.Register<MockDataStore>();
MainPage = new ImagePage();
}
}
}
Here's ImagePage.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace App1
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ImagePage : ContentPage
{
public ImagePage()
{
InitializeComponent();
var imageSource = new UriImageSource { Uri = new Uri("http://thumbs.dreamstime.com/z/watercolor-autumn-forest-landscape-sunset-hand-drawn-painting-fantasy-art-nature-beautiful-background-gouache-153834924.jpg") };
imageSource.CachingEnabled = false;
image.Source = imageSource;
}
}
}
and here's xaml for this 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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="App1.ImagePage">
<AbsoluteLayout>
<ActivityIndicator IsRunning="{Binding Source={x:Reference image}, Path=IsLoading}" AbsoluteLayout.LayoutBounds="0.5, 0.5, 100, 100" AbsoluteLayout.LayoutFlags="PositionProportional"/>
<Image IsVisible="True" x:Name="image"/>
</AbsoluteLayout>
</ContentPage>
I would greatly appreciate any help :). As I said, this is extremely simple and I have no clue why this doesn't work at this point.
What's your Xamarin.Forms version ?There is an issue reported in Xamarin.forms version 4.2.0.778463 early and that it has been fixed in the Xamarin.forms version 4.2.0.848062.
So you could try to update your Xamarin.forms version
Related
I am absolutely new to Xamarin form. I think my question that i am going to ask will be not too good but the problem i faced is very strange and i don't know how to solved it.
Problem:
I created a brand new Cross-Platform project in visual studio 2017.
and a wrote some code and when i run my application the Build Solution is failed.
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:HelloWorld"
x:Class="HelloWorld.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label x:Name="_label" Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Entry x:Name="EnterYourName" Placeholder="Write your name"/>
<Button Text="Say Hello !" Clicked="Button_Clicked" />
</StackLayout>
</ContentPage>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Form;
namespace HelloWorld
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
void Button_Clicked(object sender, EventArgs e)
{
_label.Text = "Welcome" + " " + EnterYourName.Text;
}
}
}
Errors:
All The necessary using statements are included and when i click
on build solution it give me this error...
The Type or namespace name 'System' could not found (are you missing
a using directives or assemblies reference.)
The Type or namespace name 'Xamarin' could not found (are you missing
a using directives or assemblies reference.)
Predefined type 'System.Void' is not defined or imported. and so on.
How to solve this issue ? I shall be very thankful.
Thanks.
This project is fine, so the problem is not code related (unless you have something strange in App.Xaml and App.Xaml.cs).
You may need to:
clean the project
restore Nuget packages
If the problem appears only on the single platform you might need to check your connection with Mac or see if you have installed all required Android SDK/components.
I used the labels in my xamarin page and set FontAttributes as like below code in my xaml page. By default (US culture) no issues. When i change my android device culture as french i am getting System.Reflection.TargetInvocationException. If i remove FontAttributes, it is working fine. I can't debug or get details from output window. Anyone please help on this.
My Code
<Label x:Name="continentLabel" FontAttributes="Bold"/>
I created a simple xamarin forms project and edited the xaml file as you have posted, I also added two RESX files:AppResources.resx and AppResources.fr.resx, then I set the simulator's language setting to French. It works all right. I think you may missed something, so I post my code here:
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:App34"
x:Class="App34.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Label x:Name="String1"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App34
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
String1.Text = AppResources.String1;
}
}
}
I am a newbie in Xamarin. I created a C# cross-platform project, after the project has been created there were several errors I don't know why these errors occurred. How can I fix these errors? When I click build nothing displays. When I click Play my default app does not display.
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="App1.App">
<Application.Resources>
</Application.Resources>
</Application>
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:App1"
x:Class="App1.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App1
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
}
Try to reinstall the Xamarin with Visual studio , It seems there has been something missing form installation. You can find the documentation here
https://learn.microsoft.com/en-us/xamarin/cross-platform/get-started/installation/windows
Regards
Right click on your project
Manage Nuuget Packages
Installed tab : Check if Xamarin is intalled, if yes update it, if not install xamarin
Clean and rebuild your project.
I am having trouble with Xamarin forms navigation, as in, it does not work at all.
My code :
appname.cs
using System;
using Xamarin.Forms;
namespace List
{
public class App : Application {
public App () {
MainPage = new NavigationPage (new HomePage ());
}
}
}
homepage.xaml.cs
using System;
using Xamarin.Forms;
using System.ComponentModel;
using System.Globalization;
namespace List
{
public partial class HomePage : ContentPage {
public HomePage () {
InitializeComponent ();
}
public void OnButtonClicked (object sender, EventArgs args) {
Navigation.PushAsync (new DetailsPage ());
}
}
}
My intention is obviously to open a main page, have a button on there that goes to a second page upon press.
However this happens instead whenever the button is clicked:
error message
Could not load type 'UIKit.UIView_UITextField' from assembly 'Xamarin.Forms.Platform.iOS'.
Can someone tell me what I'm doing wrong here?
Edit - code for DetailsPage, since this could be source of error:
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace List
{
public partial class DetailsPage : ContentPage
{
public DetailsPage ()
{
InitializeComponent ();
}
}
}
Edit 2 - code for Xaml pages (thanks for the help everyone, I really appreciate it):
Homepage.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:List" x:Class="List.HomePage">
<ContentPage.Title>
1
</ContentPage.Title>
<Button Text="Click Me!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Clicked="OnButtonClicked" />
</ContentPage>
DetailsPage.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="List.DetailsPage">
<Label Text="LOL"/>
</ContentPage>
In your xaml, the first element needs to be a layout (if you have multiple elements). I would try something similar to below and see if anything changes.
HomePage.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:List" x:Class="List.HomePage" Title="1">
<StackLayout>
<Button Text="Click Me!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Clicked="OnButtonClicked" />
</StackLayout>
</ContentPage>
DetailsPage.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="List.DetailsPage">
<StackLayout>
<Label Text="LOL"/>
</StackLayout>
</ContentPage>
Also, I noticed you were setting your title like using ContentPage.Title 1 ContentPage.Title. This is unnecessary. Just set the title directly in your ContentPage tag as I showed in the above example.
Well, I was having the same problem as you. I came across this solution of the xamarin guide.
It seems that in app.cs you need to call the using Xamarin.Forms.Xaml;
Right above your namespace insert [assembly:XamlCompilation(XamlCompilationOptions.Compile)]
But I really can't tell why. I'm Looking for the reason. Try to see if it resolves. In my case went well. Sorry about the bad english and the bad edit of the post, kind of new to this. But comparing all your code, it was missing this piece for you too, maybe this is the reason.
EDIT (12/01/2017) - Add
i found this, that might explain why was not working, seems like the function that we are using is part of a new set for Xamarin that helps him to became faster.
I can be wrong, if I am, please correct me someone that knows better.
Navigation.PushModalAsync(new DetailsPage());
Reference: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/introduction-to-xamarin-forms/#Navigation
What is the proper object to inherit from when trying to add a Tap handler on a map on android? I've tried with MapView, MapRenderer, MapActivity, Overlay to name a few.
CustomMapRenderer.cs
Totally wrong, but showing what I've been trying.
using Xamarin.Forms;
using nuMaps;
using nuMaps.Droid;
using Android.Gms.Maps;
using System;
using Xamarin.Forms.Maps.Android;
using Xamarin.Forms.Platform.Android;
using Android.App;
using Xamarin.Forms.Maps;
using Android.Widget;
using Android.GoogleMaps;
namespace nuMaps.Droid
{
public class CustomMapRenderer MapActivity
{
public override bool OnTouchEvent (Android.Views.MotionEvent e, Android.GoogleMaps.MapView mapView)
{
Console.WriteLine (e.Action);
return base.OnTouchEvent (e, mapView);
}
}
}
MapPage.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:nuMaps;assembly=nuMaps"
x:Class="nuMaps.MapPage">
<ContentPage.Content>
<AbsoluteLayout>
<local:CustomMap
x:Name="MyMap"
IsShowingUser="true"
MapType="Hybrid"
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
AbsoluteLayout.LayoutFlags="All"
/>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
I implemented simple extended map control to test custom map renderer. You can have a look here. Not sure if this is that you need. The only purpose of this class is to provide tap location for all three platforms. It's pure sample code, not for production, works fine for me but if you have any problems please tell me.