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

UWP release build causes runtime errors

$
0
0

When I configure my UWP app to build on release it compiles fine, but during runtime I receive lots of exceptions:

Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.PlatformNotSupportedException' in System.Private.Interop.dll
Exception thrown: 'System.AggregateException' in System.Private.Threading.dll

Why is this happening? And what should I do to resolve this problem?


cant find device.runtimePlatform

Preview of page using Control Tempate does not show controls contained in content presented.

$
0
0

Looking at this xamarin-forms-samples/Templates/ControlTemplates/SimpleTheme/

I have a control template in the resource dictionary:

    <ResourceDictionary>
        <ControlTemplate x:Key="TealTemplate">
            <Grid> <!-- omitted detail here  -->
                <ContentPresenter Grid.Row="1" Grid.ColumnSpan="2" />

If I then look a the actual page:

<ContentView x:Name="contentView" Padding="0,20,0,0" ControlTemplate="{StaticResource TealTemplate}">
    <StackLayout VerticalOptions="CenterAndExpand">
        <Label Text="Welcome to the app!" HorizontalOptions="Center" />

When I look at the previewer for the page, I only see the Control Template content, I don't see the label

Is this a bug? Intended behaviour? Or is there a way of seeing the page including control template elements and the content of the page itself.

Binding from code behind

$
0
0

I have a listview that I am binding to two different sources. I am trying to set the binding for a label field in code behind but is doesn work.

In the xaml, the first example (commented line) works, but I need to set from code. The second example (with binding removed) doesn't work.

What am I doing wrong?

Getting class not found exception when doing deeplinking

$
0
0

Hi,

I am trying to add deeplinking feature to my project.

My code in 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="com.companyname.sample">
    <uses-sdk android:minSdkVersion="15" />
    <application android:label="sample.Android">
    <activity android:icon="@drawable/icon" android:name="sample.Droid.MainActivity" android:label="sample">
      <intent-filter>
        <data android:scheme="http" android:host="www.sample.com" android:pathPrefix="/code" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
      </intent-filter>
    </activity>
  </application>
</manifest>

Mainactivity.cs

using Android.App;
using Android.Content.PM;
using Android.OS;

namespace sample.Droid
{
    [Activity(Label = "sample", 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);
            LoadApplication(new App());
        }
    }
}

Here is the sample url I am using http://www.sample.com/code/hi

When I tap on this url I am getting the following Exception:

02-08 13:16:25.168 E/AndroidRuntime(12130): FATAL EXCEPTION: main
02-08 13:16:25.168 E/AndroidRuntime(12130): Process: com.companyname.sample, PID: 12130
02-08 13:16:25.168 E/AndroidRuntime(12130): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.companyname.sample/sample.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "sample.Droid.MainActivity" on path: DexPathList[[zip file "/mnt/asec/com.companyname.sample-2/base.apk"],nativeLibraryDirectories=[/mnt/asec/com.companyname.sample-2/lib/arm, /vendor/lib, /system/lib]]
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.os.Looper.loop(Looper.java:135)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.main(ActivityThread.java:5254)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.reflect.Method.invoke(Native Method)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.reflect.Method.invoke(Method.java:372)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
02-08 13:16:25.168 E/AndroidRuntime(12130): Caused by: java.lang.ClassNotFoundException: Didn't find class "sample.Droid.MainActivity" on path: DexPathList[[zip file "/mnt/asec/com.companyname.sample-2/base.apk"],nativeLibraryDirectories=[/mnt/asec/com.companyname.sample-2/lib/arm, /vendor/lib, /system/lib]]
02-08 13:16:25.168 E/AndroidRuntime(12130):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
02-08 13:16:25.168 E/AndroidRuntime(12130):     ... 10 more
02-08 13:16:25.168 E/AndroidRuntime(12130):     Suppressed: java.lang.ClassNotFoundException: sample.Droid.MainActivity
02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.Class.classForName(Native Method)
02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
02-08 13:16:25.168 E/AndroidRuntime(12130):         ... 13 more
02-08 13:16:25.168 E/AndroidRuntime(12130):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
02-08 13:16:25.186 I/Process (12130): Sending signal. PID: 12130 SIG: 9

Anybody, please help me to solve this issue. Already lost a lot of days for this.

I am attaching a sample project with this question.

Thanks in advance :)

What is the format of android:name inside the activity,inside the application tag on manifest file

$
0
0

Dears,

I add some code to the manifest file for launch my app by tapping a url.
My code inside application tag of manifest file:

    <activity android:icon="@drawable/icon" android:name="Packagename.MainActivity" android:label="myapp">
                    <intent-filter>
                        <data android:scheme="https" android:host="www.myapp.com" />
                        <action android:name="android.intent.action.VIEW" />
                        <category android:name="android.intent.category.DEFAULT" />
                        <category android:name="android.intent.category.BROWSABLE" />
                    </intent-filter>
                </activity> 

But when I open the app in that way app breaks with an exception Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available.

I feel some mistakes in the android:name="Packagename.MainActivity" in activity tag. Is it correct? Maybe because of this getting class not found exception?

What is the correct format for android:name? "Packagename.MainActivity" or "Packagename.namespace.MainActivity" or "namespace.MainActivity" any other format? Also, the app is opening when direct tapping(I mean without url tap).

Thanks in advance :)

Showing error for Intent inside IntentFilter on Mainactivity.cs

Open my app from a url and read value from that url

$
0
0

Hi,

I want to open my app when tapping on a url and read the value appended to the url. For example, I need to get string "123" in my code by opening my app with url "myapp://open?code=123".

I add some code to manifest inside application tag :

<activity android:name="com.companyname.appname.MainActivity" android:label="appname">
        <intent-filter>
            <data android:scheme="https" android:host="appname" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>

I am testing this feature by tapping a demo url from my phone. But always open google chrome when tapping the demo url.
Thanks in advance :)


Issue with Deeplinking

$
0
0

I implement deeplinking to android part of my xamarin forms project. But when I click the url, initially it loads a black page with app name on the top, after a short period only it opens my app. I need to avoid this black screen. Also, the app opens in the same window, no new window is started for my app, if I click the url from whatsapp, the app opens in the whatsapp window.

I need a solution for these 2 problems.

Thanks in advance.

Best way to manage identity?

$
0
0

I am trying to find a way that I can integrate identity into my Forms app to look native but still be hassle free. I tried using IdentityServer4 but I'm not keen on looking after passwords and there was a lot of work involved which for one developer isn't great. So I am now looking into Azure AD B2C however I now have to go to a browser to login and I can't make the UI look native. How would I create a login experience such as the one of Facebook where it is all natively in the app using Login Providers such as Facebook, Microsoft, etc... (I understand login providers wouldn't be native, however I would want the buttons to be native) but I don't want to look after passwords. I am using ASP.Net Core as the backend api so what ever I use I need it to work with that.

Any suggestions?

Editor Width very small when empty

$
0
0

Hello,

I'm struggling with Editor component and have no clue on how to solve it.

I have an Editor (in fact an ExtEditor that inherits from Editor and has a Renderer). When the Text property is empty, the editor is very small. When I have some text in it it takes the width of this text. It has a style applied with HorizontalOptions set as FillAndExpand.

How could I set the width of this editor so it takes the available width of the container ?

Some code :

My view ; components:EditEntityPropertyRow is a composite component with a bunch of styles, and a label followed by whatever control I need in EditView, it works fine for every other kind of controls (Entry, DatePicker...) :

<?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:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:i18n="clr-namespace:Sharemat.Locales;assembly=Sharemat"
    xmlns:components="clr-namespace:Sharemat.Components;assembly=Sharemat"
    x:Class="Sharemat.Pages.Reports.ReportCreateTabs.MainTab">
    <ContentPage.Content>
        <StackLayout VerticalOptions="FillAndExpand">
            <ScrollView Padding="10, 0, 10, 0">
                <StackLayout>

                    <StackLayout BackgroundColor="White">

...

                        <components:EditEntityPropertyRow Title="{i18n:Translate Entity.Intervention.Report.Description}">
                            <components:EditEntityPropertyRow.EditView>
                                <AbsoluteLayout HeightRequest="100" HorizontalOptions="FillAndExpand">
                                    <components:ExtEditor x:Name="ReportDescriptionEditor" Text="Binding Item.ReportDescription" Style="{StaticResource EditEntityPropertyExtEditor}" />
                                    <components:MenuIcon x:Name="SpeechRecognition" IconName="speech-recognition" 
                                            HorizontalOptions="End"
                                            VerticalOptions="End"
                                            HeightRequest="60" 
                                            AbsoluteLayout.LayoutBounds="0,0,1,1" 
                                            AbsoluteLayout.LayoutFlags="All"
                                    />
                                </AbsoluteLayout>
                            </components:EditEntityPropertyRow.EditView>
                        </components:EditEntityPropertyRow>

... 

                    </StackLayout>

                </StackLayout>
            </ScrollView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

The style for EditEntityPropertyExtEditor :

            <Style x:Key="EditEntityPropertyExtEditor" TargetType="components:ExtEditor">
                <Setter Property="HorizontalOptions" Value="FillAndExpand" />
                <Setter Property="VerticalOptions" Value="FillAndExpand" />
                <Setter Property="FontSize" Value="14" />
                <Setter Property="HeightRequest" Value="100" />
            </Style>

The renderer for ExtEditor just sets a background with rounded border :

using System;

using Android.Content;
using Android.Graphics.Drawables;

using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

using Sharemat.Components;
using Sharemat.Droid.Renderers;

[assembly: ExportRenderer(typeof(ExtEditor), typeof(ExtEditorRenderer))]
namespace Sharemat.Droid.Renderers
{
    public class ExtEditorRenderer : EditorRenderer
    {
        public ExtEditorRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Editor> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null)
            {
                // Crée un drawable avec des bords arrondis
                GradientDrawable MyCornerRadiusDrawable = new GradientDrawable();
                MyCornerRadiusDrawable.SetCornerRadius(3);
                MyCornerRadiusDrawable.SetStroke(1, Xamarin.Forms.Color.Black.ToAndroid());

                // Combine les drawable
                Drawable[] DrawablesArray = { MyCornerRadiusDrawable };
                var layers = new LayerDrawable(DrawablesArray);

                // Rabougrit le padding sinon le controle prend trop ses aises
                Control.SetPadding(7, 7, 7, 7);

                // Set le background avec les drawables créés
                Control.SetBackground(layers);
            }
        }
    }
}

Foundation.MonoTouchException has been thrown in xamarin.forms

$
0
0

Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch..

I am using Prism Structure with xamarin.forms.My app is runing on android properly.when i run my app on ios then exception is occur..
i cleaned the whole project and after build all project but still error is coming..if any one has any solution then please suggest me..

Picker with ViewModel and SelectedIndex

$
0
0

Have a picker with ViewModel, populated by a Web Service (the Picker is populated by an object, that contains PolicyName, PolicyID and Description. What I want to do is be able to select the item in the Picker by the Value (ie PolicyName), not by SelectedIndex. Originally I thought I be able to use the SelectedItem (OnChangeProperty) I use in the ViewModel that I use to get the SelectedItem that the user selects. But this time, I need the ability to set SelectedItem.

Thoughts? Or I didn't explain myself too well? :)

Cam.

Picker on iOS

$
0
0

Hello,
I have a problem with iOS (Android working fine). I have a situation where I open Picker and waiting for data to load, in the meantime if I try to scroll empty picker, the app will crash. I was trying to catch the exception but with no luck.
I hope someone had the same issue before.

Can the Picker signal my VM when it gains focus?

$
0
0

Does a 'focused' event fire before 'unfocused'? I tried to move the trigger from one control over to the picker control, but I get errors when the events are fired. The build is fine, and everything works until the picker gains control. It then crashes.

FWIW, here is the code for the picker (with trigger):

<br /><Picker ItemsSource="{Binding myList}" Title="Select one" SelectedItem="{Binding myItem}">
    <Picker.Triggers>
        <EventTrigger Event="Focused">
            <local:FocusedTriggerAction />
        </EventTrigger>
    </Picker.Triggers>
    <Picker.ItemDisplayBinding>
        <Binding Path="FullName"/>
    </Picker.ItemDisplayBinding>
</Picker>


Removing shadow from android buttons

$
0
0

suddenly my buttons started showing shadows, which they didn't before. I am not sure what caused the style to change, but I would like to just have a plain rectangle with no visual effects as buttons.

i have already tried:
forums.xamarin.com/discussion/97653/button-without-shadow
alexdunn.org/2017/05/04/xamarin-tips-overriding-android-button-shadowselevation/
i.e.:

  • Creating a custom renderer that sets the Elevation property to 0 and/or sets StateListAnimator = null.
  • Setting a buttonStyle in styles.xml:
    <style name="NoShadowButton" parent="android:style/Widget.Button"> <item name="android:stateListAnimator">@null</item> </style>
    or using Base.Widget.AppCompat.Button.Borderless

but nothing is working.

I am also not looking for 'just use TapGestureRecognizers', i'd like to use buttons, this shouldn't be such a hard problem to solve.
Anyone have any tips?

tested on android 5.0.1, xamarin.forms 2.5.0.280555

Securing SQLite and .apk

$
0
0

I am preparing to release my app to the Google Play Store. I would like to know what the best practice is to secure both the .apk and the embedded sqlite database. I know I can use ProGuard, but not sure if that protects the data and was wondering if it is worth considering SQL Cipher?.
Alternatives to this are encrypting the data at row level and obfuscating the code, but ideally I would like a simple solution that protects both the source code and the database.

How can we extend FileImageSource to accept SVG files?

$
0
0

Many components of Xamarin.Forms use FileImageSource as a parameter for icons.
For example ToolbarItems passes the string to an instance of Xamarin.Forms.FileImageSource.
All my icons are in SVG format, and I don't want to convert them to dozen of ugly bitmaps versions for each devices.
I already use a component that render SVG files ( https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/SVG ).
It's a class inheriting from Image class ( SvgImage : Image ).
How can I extend Xamarin.Forms.FileImageSource to accept SVG files and render them using the SvgImage class?

Best practice for calling an Android Activity with a Dependency Service

$
0
0

I have a PCL that defines an Interface (IPictureTaker). From a viewmodel within the PCL, I use the DependencyService to call my SnapPic method :
public interface IPictureTaker { void SnapPic(); }
In the view model:

public void ExecuteMethod() { IPictureTaker pictureTaker = DependencyService.Get<IPictureTaker>(); pictureTaker.SnapPic(); }

I implement the interface in the MainActivity of the Android Project and call activity.StartActivityForResult:

`public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity, IPictureTaker
{
//OnCreate omitted

    public void SnapPic()
    {
        var activity = Forms.Context as Activity;

        var picker = new MediaPicker(activity);
        var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions
        {
            Name = "profile.jpg",
            Directory = "Krizzma"
        });
        activity.StartActivityForResult(intent, 1);
    }

protected override async void OnActivityResult(int requestCode, Result resultCode,
        Android.Content.Intent data)
    {
        if (resultCode == Result.Canceled)
            return;

        var mediaFile = await data.GetMediaFileExtraAsync(Forms.Context);

        WriteImageToDB(mediaFile);

        MessagingCenter.Send<IPictureTaker, Stream>(this, "pictureTaken", mediaFile.GetStream());

    }   

}`

My Question: I would prefer to not use the MainActivity for this purpose as I plan to have multiple interfaces similar to this one and it feels wrong to have to handle which method was called inside of the OnActivityResult. I have tried creating a "TakePictureActivity" with the exact same code and the SnapPic method is called correctly, but OnActivityResult is called in the MainAcitivty. I believe this is because Forms.Context is the MainActivity. I have tried starting the TakePictureActivity from within the SnapPic method, but was unsuccessful and it also does not seem to be the correct way to go about it.

Any suggestions on how to properly implement this would be appreciated.

Size? Thickness?

$
0
0

Hello I'm new to Xamarin Forms and I have a problem understanding what measure are those, what they mean?
When you have a thickness of 30, for example, 30 what?How do these numbers relate with the screen?

The documentation does not help in this regard.

Viewing all 77050 articles
Browse latest View live


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