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

How can I lose the white left & right margins on an iPhone

$
0
0

Android is ok, but I cannot hide the iPhone left and right margins.

I have tried applying Margin and Padding Thickness 0 to the rootStack, but the margins persist.
Any clues?

    using System;
    using Xamarin.Forms;

    namespace ContentPageExample
    {
        public class App
        {
            public static Page GetMainPage ()
            {
            var rootStack = new StackLayout
                    {
                            Orientation = StackOrientation.Vertical,
                            Spacing = 0,
                            VerticalOptions = LayoutOptions.FillAndExpand,
                            BackgroundColor = Color.Black
                    };
            var label = new Label
                {
                            Text = "Hello, Forms!",
                            VerticalOptions = LayoutOptions.CenterAndExpand,
                            HorizontalOptions = LayoutOptions.CenterAndExpand,
                        },
            rootStack.Children.Add(rootStack);
                    return new ContentPage
            {
                        Content = rootStack
            };
            //The rootStack has a white margin left and right.
            //How do I lose this?
            }
        }
    }

Why Shared Projects?

$
0
0

Maybe I am missing something wonderful about them but every example I see from Xamarin Forms is using a Shared Project. I have never found a solid reason to use a shared project, putting compiler directives through the code for each platform just seems like it will lead to hard to maintain code.

PCL's have been really easy and great for containing code. To me shared projects have no purpose other than really quick demo code but even still PCL's work with a little bit of DI doesn't make things particularly complex, especially with XF's inbuilt Dependency Service.

The question is, why does anyone use these project types, why does Xamarin keep building examples in them, which means all newcomers to XF start to use them? I honestly have never seen a reason in XF to use a shared project.

But I am ready to have my eyes opened in case I missed something with Shared Projects.

Forms Android Bug

$
0
0

Hey guys!

I'm having a really bad time with a bug that only affects android.

I have a ListView, the cells within the listview is a custom viewCell. The ViewCell has a label and an entry.

When I focus the entry i'm specting to see only once, but after shifting the focus over the entries things get werid and for example:

for the very first time, If I focus the third element, I see that the third element is focused but if i switch to another entry, lets say the fifth element, the log output is

    [0:] Focused ->3 //very first time
    09-27 09:56:18.335 W/EGL_emulation(17852): eglSurfaceAttrib not implemented
    09-27 09:56:18.335 W/OpenGLRenderer(17852): Failed to set EGL_SWAP_BEHAVIOR on surface 0x9a99d4a0, error=EGL_SUCCESS
    09-27 09:56:20.542 E/Surface (17852): getSlotFromBufferLocked: unknown buffer: 0xaee74e20
    [0:] Unfocused ->3 //switching to fifth element
    [0:] Focused ->5
    [0:] Unfocused ->5
    [0:] Focused ->3
    [0:] Unfocused ->3
    [0:] Focused ->5
    09-27 09:56:20.586 W/EGL_emulation(17852): eglSurfaceAttrib not implemented
    09-27 09:56:20.586 W/OpenGLRenderer(17852): Failed to set EGL_SWAP_BEHAVIOR on surface 0x9a7dc020, error=EGL_SUCCESS
    [0:] Unfocused ->5
    [0:] Focused ->3
    [0:] Unfocused ->3
    [0:] Focused ->5

Why is that happening?

I created a demo here

Any ideas people?

Xamarin.Forms Button with only single border on bottom

$
0
0

Hello there,

I would like to code a custom renderer to have a button with a single border on bottom.

How can i achieve that ?

Thank you !

[PRISM] Why my button is enable whereas my command should be false!

$
0
0

Hello,

I only want that my update button is active if entries are edited AND it's not the first load.
When i go on my page, data is loaded in entries and IsEdited switch to True, result my update button is active.
I have try to switch IsEdited = False; after the data load but it's not work...
Come on @NMackay ! :smile:

Best regards

My XAML:

            <StackLayout Grid.Row="0" Margin="20, 0, 20, 20" >
                <Label Style="{DynamicResource FormLabel}" Text="Nom"/>
                <Entry Style="{DynamicResource FormEntry}" Text="{Binding Lastname}" Keyboard="Default"/>
                <Label Style="{DynamicResource FormLabel}" Text="Prénom"/>
                <Entry Style="{DynamicResource FormEntry}" Text="{Binding Firstname}" Keyboard="Default"/>
                <Label Style="{DynamicResource FormLabel}" Text="Adresse électronique"/>
                <Entry Style="{DynamicResource FormEntry}" Text="{Binding Email}" Keyboard="Email"/>
                <Label Style="{DynamicResource FormLabel}" Text="Téléphone"/>
                <Entry Style="{DynamicResource FormEntry}" Text="{Binding Phone}" Keyboard="Telephone"/>
            </StackLayout>
            <StackLayout Grid.Row="1" Style="{DynamicResource BotActionBar}">
                <Button Style="{DynamicResource FormButton}" Text="Mettre à jour" Command="{Binding UpdateCommand}" HorizontalOptions="EndAndExpand"/>
            </StackLayout>

My ViewModel:

    public class ProfileEditViewModel : BindableBase
    {
        #region // Fields
        private bool _isUpdating;
        private bool _isEdited;
        private string _lastname;
        private string _firstname;
        private string _email;
        private string _phone;
        #endregion

        #region // Properties
        public INavigationService NavigationService { get; private set; }
        public DelegateCommand<string> NavigateCommand { get; private set; }
        public DelegateCommand UpdateCommand { get; private set; }

        public bool IsUpdating { get { return _isUpdating; } set { SetProperty(ref _isUpdating, value); } }
        public bool IsEdited { get { return _isEdited; } set { SetProperty(ref _isEdited, value); } }
        public string Lastname { get { return _lastname; } set { SetProperty(ref _lastname, value.NameFormat()); IsEdited = true; } }
        public string Firstname { get { return _firstname; } set { SetProperty(ref _firstname, value.NameFormat()); IsEdited = true; } }
        public string Email { get { return _email; } set { SetProperty(ref _email, value.ToLower()); IsEdited = true; } }
        public string Phone { get { return _phone; } set { SetProperty(ref _phone, value.PhoneFormat()); IsEdited = true; } }
        #endregion

        #region // Methods
        public ProfileEditViewModel(INavigationService navigationService)
        {
            NavigationService = navigationService;
            NavigateCommand = new DelegateCommand<string>(Navigate);
            UpdateCommand = new DelegateCommand(Update).ObservesCanExecute((p) => IsEdited);

            Lastname = App.API.User.Lastname;
            Firstname = App.API.User.Firstname;
            Email = App.API.User.Email;
            Phone = App.API.User.Phone;
            IsEdited = false;
        }

        private async void Update()
        {
            IsUpdating = true;
            if (await App.API.EditUserInfos(Lastname, Firstname, Email, Phone))
            {
                App.API.User.Lastname = Lastname;
                App.API.User.Firstname = Firstname;
                App.API.User.Email = Email;
                App.API.User.Phone = Phone;
                IsEdited = false;
            }
            IsUpdating = false;
        }

        private void Navigate(string s)
        {
            NavigationService.NavigateAsync(s);
        }
        #endregion
    }

Best regards

Cannot get Akavache to work using PCL Xamarin Forms app

$
0
0

I've been struggling with this for 4 hours now and I'm now turning in circles. I'm trying to get Akavache to run for my project. The project is a out-of-the-box Xamarin Forms (Portable) type. Then using Nuget I added Akavache 4.1.2 (which also added Akavache Core and SqlLite3 as well as ReactiveUI and Splat). I then updated Splat because the dependency in the nuget package is wrong (was 1.3.3 but should have been 1.6.0). But still I'm getting an error launching this app (targeting iOS for now) when adding the first line that you should have to target this (BlobCache.ApplicationName = "MyApp"):

System.TypeInitializationException: The type initializer for 'Akavache.BlobCache' threw an exception. ---> System.Exception: Failed to initialize Akavache properly. Do you have a reference to Akavache.dll?
  at Akavache.Sqlite3.Registrations.Register (IMutableDependencyResolver resolver) [0x0001f] in <filename unknown>:0
  at Akavache.DependencyResolverMixin.InitializeAkavache (IMutableDependencyResolver This) [0x000c0] in <filename unknown>:0
  at Akavache.BlobCache.<.cctor>b__0 () [0x0000d] in <filename unknown>:0
  at Splat.Locator.RegisterResolverCallbackChanged (System.Action callback) [0x00039] in <filename unknown>:0
  at Akavache.BlobCache..cctor () [0x00018] in <filename unknown>:0

Anyone any ideas?

Max length on Entry

$
0
0

Is there a way to limit the length of text in an Entry control? If not, is it planned to add this feature?

[Xamarin.Forms] CarouselPage Swipe Animation

$
0
0

Using a PCL project I implemented a simple Application using Carousel Page. The swipe animation works fine on iOS (considering the speed of swiping), however when it comes to Android the animation doesn't seem to work if I speed up the gesture I end up with a view replacing another without any animation. In addition I receive this message :

W/OpenGLRenderer( 5533): Incorrectly called buildLayer on View: LinearLayout, destroying layer...


What is a good library to use for MVVM with Xamarin Forms

$
0
0

Hi,

I am getting started on Xamarin and decided to use Xamarin Forms. What is the good MVVM library to use for Xamarin.Forms?

My service and board cast stop working if the apps killed

$
0
0

thank you on advance
I have Issue and I hope u can help me
I m trying to design a service on android to check the httpclient every 10s and notify the the user. the application working find until I kill the apps.

can anyone help me

this my activity :

`using System;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Lawyer.Droid
{
[Activity(Label = "Lawyer.Droid",LaunchMode=Android.Content.PM.LaunchMode.SingleTop, Icon = "@drawable/icon", Theme = "@style/MyTheme", 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());


        StartService(new Intent(this, typeof(myservice)));



    }
}

}
`

this is my service

using System.Threading;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.Widget;
namespace Lawyer.Droid
{
[Service(Enabled = true,Exported = true, Name = "lawyer.Droid.myservice")]
class myservice : IntentService
{
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{

        new Task(() =>
            {
                while (true)
                {
                     Intent intents = new Intent();
                     intents.SetAction("com.alr.text");
                        //intents.PutExtra("MyData", "Data from service");
                     SendBroadcast(intents);
                    Toast.MakeText(this, "sufyan", ToastLength.Long);
                    Thread.Sleep(10000);
                }

            }).Start();


        return StartCommandResult.Sticky ;
    }

    protected override void OnHandleIntent(Intent intent)
    {

    }

}

this is my board cast :

using System.Collections.Generic;
using System.Net.Http;
using Android.App;
using Android.Content;

using Newtonsoft.Json;

namespace Lawyer.Droid
{
public class Myreciver
{

    //public Myreciver()
    [BroadcastReceiver(Exported = true, Label = "SMS Receiver")]

    [IntentFilter(new string[] {"com.alr.text"})]
    [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]


    //[IntentFilter(new string[] {  "Android.Content.Intent.ActionBootCompleted" })]
    public class SMSReceiver : Android.Content.BroadcastReceiver
    {

        string content1;
        public int d1;
        public override void OnReceive(Context context, Intent intent)
        {

            // Log.Info(Tag, "Intent received: " + intent.Action);
            // read the SendBroadcast data
            if (intent.Action == "com.alr.text")
            {
                // check the data count is null
                if (Lawyer.EmptyClass.Data_count_1 == "")
                {
                    Lawyer.EmptyClass.Data_count_1 = "0";
                }
                // call the php code
                sendtophp();
                if (d1 <= System.Convert.ToInt32(Lawyer.EmptyClass.Data_count_1))
                {

                }
                else {


                    // Start main Activity (you can replace with whatever Activity you want here)
                    var intent1 = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);
                    intent1.AddFlags(ActivityFlags.ClearTop);

                    var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.UpdateCurrent);

                    var context1 = Android.App.Application.Context;
                    var builder = new Android.App.Notification.Builder(context1)
                        .SetSmallIcon(Resource.Drawable.icon)
                        .SetContentTitle("My application")
                        .SetDefaults(NotificationDefaults.Sound)
                        .SetContentText(Lawyer.EmptyClass.Data_count_1)
                        .SetOngoing(true);
                    var not = builder.Build();
                    NotificationManager notManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                    notManager.Notify(1, not);
                    Lawyer.EmptyClass.Data_count_1 = d1.ToString();


                }
            }
            //read incomming sms

        }
        public async void sendtophp()
        {


            var client = new HttpClient();
            try
            {
                var response = await client.GetAsync("url");
                if (response.IsSuccessStatusCode)
                    content1 = await response.Content.ReadAsStringAsync();
                var result = JsonConvert.DeserializeObject<List<MSG>>(response.Content.ReadAsStringAsync().Result);

                d1 = result.Count;
            }
            catch (System.Exception e)
            {

            }
        }



        public class MSG
        {
            public string date { get; set; }
            public string text { get; set; }
            public string text1 { get; set; }
            public string user { get; set; }
            public string password { get; set; }
        }
    }

}

}

I keep getting XamlFilePathAttribute class not found error when modifying Xaml files

$
0
0

This attribute was introduced in November. Somehow it get's injected in my generated cs files for my xaml views but the compiler has no clue where to find the attribute. I suppose I have a versioning problem. Is it possible to get the versions where this was introduced in tools and in the libraries please?

UrhoSharp.Forms Access Violation Exception

$
0
0

I keep encountering an exception when running my Xamarin.Forms application since using the Urho.Forms package.

An exception of type 'System.AccessViolationException' occurred in Urho.Forms.dll but was not handled in user code

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Stack Trace:

at Urho.Node.Node_AddComponent(IntPtr handle, IntPtr component, UInt32 id, CreateMode mode)
at Urho.Node.AddComponent(Component component, UInt32 id, CreateMode mode)
at Urho.Node.CreateComponent[T](CreateMode mode, UInt32 id)
at SavantX.StaticScene.<CreateScene>d__4.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(Object stateMachine)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

How to make iOS device vibrate even when ringer is turned on

$
0
0

I am using the Vibrate plugin created by @JamesMontemagno . On iOS, I find that the vibration only happens if the ringer sound is turned off. Is there any way of getting vibration to work on iOS regardless of the ringer setting?

Font Awesome not working in iOS

$
0
0

Hello Guys,

I am using font awesome for fonts in application.
These fonts are working fine on ios emulator,
But when I create .ipa file and install that on iPhone then those fonts are not working.
Except the font it shows "?" images.

I added "fontawesome.ttf" in resource folder.
Also edited "Info.plist" file.

Plz help me out.

Java.Lang.NoSuchMethodError

$
0
0

Java.Lang.NoSuchMethodError: no static method "Landroid/text/Html;.fromHtml(Ljava/lang/String;I)Landroid/text/Spanned;"

I'm getting this error on Android 6 and older. On Android 7 it works.
This is happening on a Label Renderer for Android, running this command:

Html.FromHtml(myText, FromHtmlOptions.ModeCompact)

I'm using the Xamarin.Forms version 2.3.3.180, Xamarin.Android 7.0.2.42 and Xamarin 4.2.2.11

Any ideas?


Shared aplication problem

$
0
0

Hello.

I have trial version of xamarin and I have stuck on tests phase. I spent a few hours on that.

I've created "Shared" solution from scratch.

When solution is generated I can compile and run on android as well as on IOS.

Problem is starting when I add to shared project "Forms ContentPage xaml".

During compilation error ocured:

.../MyPage.xaml.cs(4,4): Error CS0103: The name `InitializeComponent' does not exist in the current context (CS0103) (XformTest.iOS)

Error is showing in .IOS project for Android project is ok.

Other strange behavior is when I close this solution and reopen.

After that error was changing to:

Error CS1508: The resource identifier `XformTest.iOS.MyPage.xaml' has already been used in this assembly (CS1508) (XformTest.iOS).

I cannot grasp what happening here.

Regards.

Paweł Stępień

Facebook SDK and FormsApplicationDelegate

$
0
0

I know that is a noob question but what's the best approach to use Facebook SDK and Xamarin Forms on AppDelegate?

Currently I'm doing this way:

public override bool FinishedLaunching(UIApplication application, NSDictionary options)
{
    ApplicationDelegate.SharedInstance.FinishedLaunching(application, options);
    return base.FinishedLaunching(application, options);
}

But for unknown reason the app is crashing when I try to call LoginManager.LogInWithReadPermissionsAsync without any exception.

I think that the problem is associated with ApplicationDelegate.SharedInstance.FinishedLaunching(application, options); but I'm not sure.

Tks for any help.

Xaml Compilation - Object reference not set to an instance of an object

$
0
0

When trying to use XAML Compilation i always get this issue when building:

1> Module: TestApp.dll
1> Resource: TestApp.Page1.xaml...
1> Parsing Xaml... done.
1> Replacing Page1.InitializeComponent ()... failed.
1> C:\ProyectosInvestigacion\TestApp\TestApp\TestApp\TestApp.Page1.xaml : error : Object reference not set to an instance of an object.
1> at Xamarin.Forms.Build.Tasks.SetNamescopesAndRegisterNamesVisitor.CreateNamescope()
1> at Xamarin.Forms.Build.Tasks.SetNamescopesAndRegisterNamesVisitor.Visit(RootNode node, INode parentNode)
1> at Xamarin.Forms.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
1> at Xamarin.Forms.Build.Tasks.XamlCTask.Compile()

I've done a simple TestProject in which i added one Xaml page and configured it to compile:

    [XamlCompilation(Xamarin.Forms.Xaml.XamlCompilationOptions.Compile)]
    public partial class Page1 : ContentPage
    {
        public Page1()
        {
            InitializeComponent();

        }
    }

And the Xaml here:

<?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="TestApp.Page1">
  <Label x:Name="lblText" Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>

This always throws "Object reference not set to an instance of an object" on the Error List using Visual Studio 2013, Xamarin Forms 2.1.0.6529
I'm attaching the whole solution so anyone can reproduce this error.

Is there a known way to get Xaml Compilation working?

Remove gap between toolbar and tabs

$
0
0

I recently started exploring Xamarin.Forms again and I ran into an issue when using custom tabs and toolbar layout overrides. You can see the result below:
image

The following makes up the tabs.axml and the toolbar.axml under .\Resources\layout.

tabs.axml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabIndicatorColor="@android:color/white"
    app:tabGravity="center"
    app:tabMode="fixed"
    android:padding="0dp" />

toolbar.axml

<?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" />

MainActivity.cs:

FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;
FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;

base.OnCreate (bundle);

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

LoadApplication (new App ());

Does anyone have any suggestions? If I can't get this resolved quick, I'm going to have to go back to platform independent UI's.

I honestly do not know what is causing this.

my master page overlap to upper status bar.

$
0
0

my master page overlap to upper status bar. how to overcome top space in master datail page

Viewing all 91519 articles
Browse latest View live


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