Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 77050 articles
Browse latest View live

Xamarin Media Plugin doesn't works on Android

$
0
0

Hi,
I've installed the plugin "Xam.Plugin.Media".
The plugin works fine on IOS but on Andorid the app crash as soon it starts.

I have followed the readme.txt that come after the installation of the plugin, so my files are:

MainActivity.cs:

using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Plugin.Permissions;
using Plugin.Permissions.Abstractions;
using FFImageLoading.Forms.Droid;

namespace SgatMobileV2.Droid {
    [Activity(Label = "SgatMobileV2", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity {
        protected override void OnCreate(Bundle bundle) {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            CachedImageRenderer.Init(enableFastRenderer: true); // Inizializza il plugin FFImageLoading

            LoadApplication(new App());
        }

        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, global::Android.Content.PM.Permission[] grantResults) {
            PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}

Resources/xml/file_paths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <external-files-path name="my_images" path="Pictures" />
  <external-files-path name="my_movies" path="Movies" />
</paths>

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="it.volos.SgatMobile" android:installLocation="auto">
  <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="26" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <application android:label="SgatMobileV2.Android" android:icon="@drawable/icon">
    <provider android:name="android.support.v4.content.FileProvider" android:authorities="it.volos.SgatMobile.fileprovider" android:exported="false" android:grantUriPermissions="true">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
    </provider>
  </application>
</manifest>

But after the app starts, this error is triggered:

System.NullReferenceException: Object reference not set to an instance of an object.

Can anyone help me please?

Thank you!


NavigationPageRenderer - OnAttachedToWindow - Sequence contains no elements

$
0
0

We changed some code and now the Android app crashes on startup. This is what I got from the log:

Time Device Name Type PID Tag Message
07-26 10:14:26.356 LGE Nexus 5X Info 27331 MonoDroid System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Last[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00010] in :0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnAttachedToWindow () [0x00011] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:211
at Android.Views.View.n_OnAttachedToWindow (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9ab9faae1b4b4f0da28e7c4ac61e2c78>:0
at (wrapper dynamic-method) System.Object:d392ac44-8ad7-4f92-9fdf-b7aceefc1fe7 (intptr,intptr)

I can see the code here:
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs

But, I'm powerless to stop the bug or detect why it is occurring. Could someone at Xamarin please put a better validation error message in this method? Or, could someone please recommend a work around? This code works fine on UWP.

How to implement autobackup in xamarin android project?

$
0
0

I went through the official android documentation for auto backup for android 6 and higher. it says that only thing required is to add into the manifest but this doesnt work somehow for me or i dont know what I should expect with that.

<manifest ... >
    ...
    <application android:allowBackup="true" ... >
        ...
    </application>
</manifest>

For example, when I look at whatsapp, under my google drive, i can see whatsapp backup together with my phone name backup. So question is my app is backed up into my phones full backup or doing that I expect a separate backup like whatsapp.

2nd question, whatsapp has options to change gmail account, frequency etc. How can we do it for our app? implementing xamarin.auth with google login can help but which api is it to change settings for backup?

iOS Map Memory Leaks

$
0
0

I'm running the latest version for Forms and iOS, and I am seeing VKMapView crashes occurring on iOS when navigating between pages with Map controls on them.

Anyone else seeing this behavior? If so, are there are any workarounds? I've included my crash log.

Thread 0 name: tid_303 Dispatch queue: com.apple.main-thread
Thread 0:
0 libc++.1.dylib 0x00000001833b7fcc std::1::__shared_weak_count::lock() + 4
1 VectorKit 0x0000000194096174 gss::StylesheetManager::clearCaches() + 88
2 VectorKit 0x0000000194091628 -[VKMapModel flushCaches:] + 140
3 VectorKit 0x000000019404a300 md::CartographicRenderer::prune(md::PruneLevel) + 44
4 VectorKit 0x0000000194055e00 -[VKMapView didReceiveMemoryWarning:] + 232
5 VectorKit 0x0000000194194d84 -[VKMemoryObserver triggerMemoryNotification:] + 116
6 VectorKit 0x0000000194194e30 __56-[VKMemoryObserver initWithTarget:selector:taskContext:]_block_invoke + 44
7 libdispatch.dylib 0x0000000183b36a14 _dispatch_client_callout + 12
8 libdispatch.dylib 0x0000000183b73640 _dispatch_continuation_pop$VARIANT$armv81 + 416
9 libdispatch.dylib 0x0000000183b7c858 _dispatch_source_invoke$VARIANT$armv81 + 524
10 libdispatch.dylib 0x0000000183b77b64 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 680
11 CoreFoundation 0x0000000184162544 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
+ 8
12 CoreFoundation 0x0000000184160120 __CFRunLoopRun + 2008
13 CoreFoundation 0x000000018407fe58 CFRunLoopRunSpecific + 432
14 GraphicsServices 0x0000000185f2cf84 GSEventRunModal + 96
15 UIKit 0x000000018d7d467c UIApplicationMain + 232

Using Visual Studio 2017, any coding error results in "The application is in break mode"

$
0
0

Take the following code:
var x = new List();
var y = x[3];

When debugging a UWP project, Visual Studio stops on the offending line and produces the expected error: "System.ArgumentOutOfRangeException: 'Index was out of range..."

Using the same solution, Android or iOS project, instead of breaking on the incorrect code, Visual Studio displays the "Break Mode" tab with "The application is in break mode". The Exception details only state "An unhandled exception occurred"

Anyone have any idea how to get Visual Studio to break on the offending line?

How to make a squared image to a round image on xamarin forms ?

$
0
0

Is it possible to make a round image on Xamarin Forms of a squared image. I have a lot of images which should be displayed as a circle on ListView along with its name etc. But how can I do this?


<Ellipse.Fill>

</Ellipse.Fill>

I tried like this, but it is not working and it threw an error "Type ImageBrush not found in xmlns http://xamarin.com/schemas/2014/forms"

Is there a way to grayscale an image in Xamarin Forms?

$
0
0

You know how you can disable buttons and they have a disable color. Well lets say we have an image on a row that I also want to turn black and white depending on if that item is active or not. Is there anything available for this?

Android Form Keyboard Scroll

$
0
0

Hi guys,

I'm having a problem with a simple form. When an entry is clicked and the keyboard pops up, the toolbar just scrolls up and I can't scroll up to the next field. I am using the toolbar layout for Android and I'm suspecting that it might have something to do with this.

My structure:
Relative Layout -> Scrollview Layout -> Stacklayout -> bunch of entries

The axml Android Layout I'm using is the following:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />

Has anyone been experiencing the same problems?

Thanks
Shaun


Where is the build log?

$
0
0

When I'm running a Xamarin forms app via my iOS Emulator with Visual Studio on Windows, where specifically do I view the build log? Is it on my windows box or over on the mac mini that I have attached?

I'm getting an error that states: Native linking failed. Please review the build log

I'm not talking about the output window, but rather the build log they are referring to.

How to get Height and Width in UWP Custom Renderer Control

$
0
0

I have a UWP custom renderer that I am perform some drawing in the native control based on a UWP Canvas. I need the height and width of the Xamarin.Forms.View so that I can adjust my drawing accordingly. I have tried passing the Element height and width to the control but it always has a value of -1. In iOS renderer I send in the UIView.Bounds and in Android you pass the context and override OnDraw which has the Android Canvas which gives you this values. So does anyone know how to get the same values from UWP in the renderer? I have tried for hours to get the height and width of the View.

Orgbrat

Generating custom pins from using longitude and latitude values from a database.

$
0
0

Hi all, I'm currently working on a project in which I am using a custom map renderer with custom pins. I am using a firebase database to store the information. I was just wondering if there is a way to generate x amount of pins using the longitude and latitude values they have. I've been stuck on this for a while and cant seem to find the answer anywhere online.

Cheers!

PopAsync does not go back to pervious page

$
0
0

There are 3 pages in the navigation stack, a, b and c. When I use Navigation.PopAsync() inside c, c is removed from the stack but does not go back to the pervious page b.

I want to create a regular expressions

$
0
0

I want to create two regular expressions which is take the value between 0 to 90 only and other is 0 to -180 only & take 6 digit only after .(dot)

Xamarin.Form Error: Failure [INSTALL_FAILED_INVALID_APK: Package couldn't be installed.

$
0
0

I am getting couple of errors while trying to run xamarin forms app on android emulator:

A> Got this error randomly:
**Failure [INSTALL_FAILED_INVALID_APK: Package couldn't be installed in /data/app/App2.Android-1: Package /data/app/App2.Android-1/base.apk code is missing] **

B>**The "LinkAssemblies" task failed unexpectedly.
**1>System.IO.IOException: The process cannot access the file 'obj\Debug\android\assets\App2.Android.dll' because it is being used by another process.
1> at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1> at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
1> at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
1> at Xamarin.Android.Tools.Files.CopyIfChanged(String source, String destination)
1> at Xamarin.Android.Tasks.MonoAndroidHelper.CopyIfChanged(String source, String destination)
1> at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
1> at Xamarin.Android.Tasks.LinkAssemblies.Execute()
1> at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1> at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
1>Done building project "App2.Android.csproj" -- FAILED.

A have already tried by increase Java Max heap size to 1048 but still getting this error frequently.

Sometimes I am able to run xamarin forms app by cleaning and closing the solution and rebuild it.
Also I am not able to show data inside ListView. Here is my sample code:

MainPage.Xaml
<?xml version="1.0" encoding="utf-8" ?>

<ContentPage.Content>

<Grid.RowDefinitions>

</Grid.RowDefinitions>

<ListView.ItemTemplate>

<ViewCell.View>

</ViewCell.View>

</ListView.ItemTemplate>

</ContentPage.Content>

MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace App2
{
public partial class MainPage : ContentPage
{
public List NameList { get; set; }
public MainPage()
{
NameList = new List();
NameList.Add(new Name { FirstName = "aaaa" });
NameList.Add(new Name { FirstName = "bbbb" });
NameList.Add(new Name { FirstName = "ccccc" });
InitializeComponent();
}
protected override void OnAppearing()
{
BindingContext = NameList;
base.OnAppearing();

}

}
public class Name
{
public string FirstName { get; set; }
}

}

It is a PCL project.
I am using latest xamarin version, jdk 1.8, Android 7.1 platform.
Android emulator running on API level 25, using host GPU and 2048 RAM.
**
** Please help**

Expandable ListView with Master Detail Page

$
0
0

Hi
How can I apply expandable listview for master detail page?
Sub list inside main list which show or hide when click.
Like picture


How to add image in navigation bar (Title bar) in xamarin.forms

$
0
0

Hi,

How to add image in navigation bar (Title bar) in xamarin.forms?

The type or namespace name 'Xamarin' could not be found

$
0
0

i've Created a xamarin Cross-platform solution (Blank) and it runs normally on android emulator whenever i try to run it on xamarin Live Player i get the below errors

1- AppDelegate.cs(1,1): error: The type or namespace name 'Xamarin' could not be found in the global namespace (are you missing an assembly reference?)
2- AppDelegate.cs(1,1): error: 'AppDelegate.FinishedLaunching(UIApplication, NSDictionary)': no suitable method found to override
3- AppDelegate.cs(1,1): error: The name 'LoadApplication' does not exist in the current context
4- AppDelegate.cs(1,1): error: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)

i'm running VS 2017 ENT 15.5.6 on Windows 10 Pro. and everything is updated

ObservableCollection.AddRange()

$
0
0

If your Models expose an ObservableCollection, and you are adding lots of elements, you don't want this adding to fire a UI event every time.

You can use this ObservableCollection which only notifies the UI to update after all the elements are updated when AddRange is used:

public class ObservableCollectionFast<T> : ObservableCollection<T>
{
    public ObservableCollectionFast()  : base()   {   }

    public ObservableCollectionFast(IEnumerable<T> collection)  : base(collection)   {    }

    public ObservableCollectionFast(List<T> list)   : base(list)  {        }

    public void AddRange(IEnumerable<T> range)
    {
        foreach (var item in range)
        {
            Items.Add(item);
        }

        this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
        this.OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
        this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
    }

    public void Reset(IEnumerable<T> range)
    {
        this.Items.Clear();

        AddRange(range);
    }
}

Xamarin.Forms.DefaultItems.props not found

$
0
0

Hi,

So, I have been trying to fix this error I am getting over a month now, but with no success. I am currently working on a personal app project in collaboration with a few of my other developer friends and surprisingly the project compiles perfectly fine on my friends machine.

The following is the error I am getting:

"The imported project "C:\Users\divye\Documents\NHSF Xamarin App\packages\Xamarin.Forms.2.5.0.280555\build\netstandard1.0\Xamarin.Forms.DefaultItems.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk".

I can't understand why my code will not compile. I have gone through lots and lots of Stack Overflow posts and tried pretty much all the proposed solutions without any success. As a last resort I am having to post on here. I have also posted on Stack Overflow too.

I have tried the following:

  • Deleted the project locally from my machine and re-cloned the git repository and then tried running the project
  • Cleaned the project out and tried rebuilding again
  • Have spoken with my friend who is also working on the project, and matched my local project set out to his
  • I have gone into the Xamarin.iOS and Xamarin.Android .csproject files and also manually added in the Import statement for 'Xamarin.Forms.DefaultItems.props'
  • I have manually checked the folder '$..\netstandard1.0\ folder path to make sure the 'Xamarin.Forms.DefaultItems.props' file physically exists in the folder and it does for both iOS and Android.
  • Updated all packages in Xamarin Studio for the project to make sure latest versions of the packages are being used
  • Downgraded the Xamarin.Forms package to see if it could be to do with a bug in the latest package but this does not seem to be the issue.
  • A suggested fix that worked for my friend was recreating the project to contain the ASP.NET backend for mobile packages. I have tried this as well.
  • I was initially getting the error on my Mac so I thought I would give it a go on my Windows machine. Same thing happens on there too.

I am stumped at the issue. It is failing to build at all. Neither iOS or Android work.

I am hoping someone from here can help.

Thanks,

Divyesh!

Using declarative style C# instead of XAML - should Xamarin redirect XAML efforts elsewhere?

$
0
0

Introduction

Miguel tweeted:
"I should have never added Xaml and instead invented our own ...", expressing regrets about having to deal with XAML (standardization) problems.

My response was:
"I would applaud dropping XAML altogether. Advancements in C# (declarative syntax) have eliminated any advantages of a separate markup language for years. Why would you want to hand-code an object serialization format? Why waste time on duplicating dev tools for features that c# already offers?"

David expressed an interest to see how I have been creating Xamarin Forms markup in declarative style C#, instead of in XAML, for the past few years. So I write this post to provide a concrete example, and share the reasoning behind my remark (which was deliberately lacking nuance - it is Twitter after all).

Redirecting Xamarin IDE team effort

Why do I spend time on this? In the past years I only experienced advantages from using declarative C# instead of XAML. Given that the core challenge for the Xamarin IDE teams remains to improve the developer productivity, I would love to see some of the effort now being spent on (imo redundant) XAML tooling to be redirected towards reducing IDE bugs and speeding up the dev cycle, i.e. Live Player.

I recently investigated Google's Flutter (build beautiful native apps in record time), which by design has no separate language for markup and which offers hot reload - which is like a Xamarin Live Player without any limitations and a refresh time of 400-600 ms (I checked on devices and emulators). This is what I want from Xamarin!

This is the competition Xamarin is facing today. Some developers are already switching from Xamarin to Flutter because of developer tooling productivity, which apparently can be more important than language or framework or experience. As a Xamarin veteran, I get why they do this. I feel that unless there is a significant team increase, Xamarin needs to focus and redirect existing effort towards developer productivity, meaning less IDE bugs and faster development cycle.

Example
.
Here is an unabridged example of a simple registration code page in a production app I wrote:

Content = new Grid { 
    RowSpacing = 0, 
    RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition {}},
    Children = {
        PageHeader.Create(PageMarginSize, nameof(vm.RegistrationTitle), returnToPreviousViewCommandPropertyName: nameof(vm.CancelEnterRegistrationCodeCommand), centerTitle:true),

        new ScrollView { Content = new Grid {
            RowDefinitions = {
                new RowDefinition { Height = 170 },

                new RowDefinition { Height = 75 },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto }
            },
            RowSpacing = 0,

            ColumnDefinitions = {
                new ColumnDefinition { Width = 160 },
                new ColumnDefinition { }
            },

            Children = {
                new Label {
                    Margin = fieldNameMargin, LineBreakMode = LineBreakMode.WordWrap, 
                    HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, HorizontalTextAlignment = TextAlignment.Center, 
                }.SetFontSize(WspFontSizes.Size15)
                 .SetColRow(0, 2, 0, 1)
                 .Bind(nameof(vm.RegistrationPrompt)),

                new Label { Text = "Registration code", VerticalOptions = LayoutOptions.End, Margin = fieldNameMargin }.SetFontSize(WspFontSizes.Size13)
                .SetColRow(0, 1, 1, 2),
                new Label { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.End, Margin = fieldNameMargin }.SetFontSize(WspFontSizes.Size13)
                .SetColRow(1, 2, 1, 2)
                .Bind(nameof(vm.RegistrationCodeValidationMessage)),

                new Entry {
                    Placeholder = "E.g. 123456", HeightRequest = 44, Keyboard = Keyboard.Numeric, 
                    BackgroundColor = WspColors.White.ToColor(), TextColor = WspColors.Gray1.ToColor(), Margin = fieldMargin }.SetFontSize(WspFontSizes.Size15)
                .Bind(nameof(vm.RegistrationCode), BindingMode.TwoWay)
                .Id(AId.RegistrationCodePage_CodeEntry)
                .SetColRow(0, 2, 2, 3),

                new Button {
                    Text = "Verify",
                    Margin = PageMarginSize,
                    HeightRequest = 44,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    TextColor = WspColors.White.ToColor(),
                    BackgroundColor = WspColors.ColorValueAccent.ToColor()
                }.SetFontSize(WspFontSizes.Size13)
                 .Id(AId.RegistrationCodePage_VerifyCodeButton)
                 .Bind(Button.IsVisibleProperty, nameof(vm.CanVerifyRegistrationCode))
                 .Bind(nameof(vm.VerifyRegistrationCodeCommand))
                 .SetColRow(0, 2, 3, 4),
            }
        }}.SetColRow(0, 1)
     }
 };

Nothing advanced is going on here, I use standard C# language features to reuse controls (e.g. PageHeader.Create method ) and to simplify data binding (.Bind extension methods). In my eyes the above reads similar to equivalent XAML.

Which is not very surprising given that XAML is at its heart just an object serialization format in XML. In other words, XAML does what the new keyword in C# does.

Now, C# is designed for humans; while XML is better for tools such as visual designers. As a matter of fact, that was the vision for (WPF) XAML: that human designers could use a tool (Blend) to create a UI that developers could consume. However, I experienced how that vision, even in the best possible time and scenario, failed to deliver (I Built a WPF app for Windows tablet together with a XAML book authoring, leading designer, who was a master in Blend, when that was THE tool. The UI was beautiful and totally unmaintainable). So even if there would come an ultimate visual designer tool for Xamarin Forms, equivalent to the best that Blend ever was, it would still fail for the same reasons. Time to move on, like Flutter?

So, anyone (Xamarin devs and Xamarin team) wants to chime in on either XAML versus C# or redirecting Xamarin IDE efforts?
I'm really curious how Xamarin devs (especially experienced ones) see this.

Thanks!

Viewing all 77050 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>