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

how to SetOnClickListener in FrameRenderer?

$
0
0

I have that code below works for button but i would like to change button to frame.
Does anybody know how to convert it? I cant figure out SetOnClickListener part as it is not exist in framerenderer?

using System;
using Android.App;
using Android.Content;
using Xamarin.Forms.Platform.Android;
using Object = Java.Lang.Object;
using View = Android.Views.View;
using Xamarin.Facebook;
using Android.Widget;
using myApp.Authentication;
using myApp.Droid.Authtentication;

[assembly: Xamarin.Forms.ExportRenderer(typeof(FacebookLoginButton), typeof(FacebookLoginButtonRendererAndroid))]
namespace myApp.Droid.Authtentication
{
    public class FacebookLoginButtonRendererAndroid : ButtonRenderer
    {
        private static Activity _activity;
        Context _Context;
        public FacebookLoginButtonRendererAndroid(Android.Content.Context context)
                 : base(context)
        {
            _Context = context;
        }

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

            _activity = _Context as Activity;

            //DEBUG
            //Xamarin.Facebook.Login.LoginManager.Instance.LogOut();

            if (this.Control != null)
            {
                Button button = this.Control;
                button.SetOnClickListener(ButtonClickListener.Instance.Value);
            }

            if (AccessToken.CurrentAccessToken != null)
            {
                App.PostSuccessFacebookAction(AccessToken.CurrentAccessToken.Token);
            }
        }

        private class ButtonClickListener : Object, IOnClickListener
        {
            public static readonly Lazy<ButtonClickListener> Instance = new Lazy<ButtonClickListener>(() => new ButtonClickListener());

            public void OnClick(View v)
            {
                var myIntent = new Intent(_activity, typeof(FacebookActivity));
                _activity.StartActivityForResult(myIntent, 0);
            }
        }
    }
}

Xamarin Forms SQLite Query

$
0
0

Hello everyone!
I'm new to Xamarin and I'm making a application but I'm having some problems with SQLite.
I'll explain the problem first, and I'll add my code below. So basically, I'm able to save a user into my SQLite database but after this, I want to take a part of that user and display it in a label. I'll illustrate:
for example, I save a user with fields:
'Voornaam': Duke
'Achternaam': Decker
....

So now the user is saved, I would like to get the field 'Voornaam' from my table Users where this user is saved. I think I know how to select the name but then I need to convert this object into a string or something. I know it may sound confusing but maybe someone will be able to help me.

Here's some code to give an idea of what I want to do:

My query class:

`public class Ride2EarnDatabase
{
static object locker = new object();
readonly SQLiteAsyncConnection database;
readonly SQLiteConnection db;

    public Ride2EarnDatabase(string dbPath)
    {
        database = new SQLiteAsyncConnection(dbPath);
        database.CreateTableAsync<Rit>().Wait();
        database.CreateTableAsync<Gebruiker>().Wait();
    }

    public Ride2EarnDatabase()
    { }

    public Task<List<Rit>> GetRitAsync()
    {
        return database.Table<Rit>().ToListAsync();
    }

    public Task<int> SaveRitAsync(Rit a)
    {
        if (a.ID != 0)
        {
            return database.UpdateAsync(a);
        }
        else { return database.InsertAsync(a); }
    }

    public Task<int> SaveGebruikerAsync(Gebruiker a)
    {
        if (a.ID != 0)
        {
            return database.UpdateAsync(a);
        }
        else { return database.InsertAsync(a); }
    }

    public Task<List<Gebruiker>> GetGebruikerAsync()
    {
        return database.Table<Gebruiker>().ToListAsync();
    }

    /*public Task<List<Gebruiker>> GetVoornaam()
    {
        return database.QueryAsync<Gebruiker>("SELECT [Voornaam] FROM [Gebruiker]");
    }*/

    /*public IEnumerable<Gebruiker> QueryValuations()
    {
        return db.Query<Gebruiker>("select Voornaam from Gebruiker");

    }*/
}`

My class to convert my object to string (don't even know for sure if this is the way to do it, correct me if I'm wrong):

`public class Business
{
private Task<List> _Voornaam;
private IEnumerable _Test;
private Ride2EarnDatabase _db;

    public Task<List<Gebruiker>> Voornaam
    {
        get { return _Voornaam; }
        set { _Voornaam = value; }
    }

    public IEnumerable<Gebruiker> Test
    {
        get { return _Test; }
        set { _Test = value; }
    }

    public Business()
    {
        _db = new Ride2EarnDatabase();
        //_Voornaam = _db.GetVoornaam();
        //_Test = _db.QueryValuations();
    }

    /*public string VoornaamWeergeven()
    {
        string a = string.Empty;
        Voornaam.
        foreach (Gebruiker b in Voornaam)
        {
            a = b.Voornaam;
        }
        return a.ToString();
    }*/

    public string VoornaamWeergeven()
    {
        string a = string.Empty;
        foreach (Gebruiker b in Test)
        {
            a = b.ToString();
        }
        return a;
    }
}`

I think these are the most important ones, I can add more code if needed.
I would be so grateful if someone would be able to help me!

Master Detail Page

$
0
0

Hi is it possible to make another master detail page after a successful login? because the content of the second master detail page slide-in-menu will be different from the default slide-in-menu or change the content of the slide menu of masterdetailpage after logged in

help, I need to draw regtangles in an image

$
0
0

Greetings friends. I am working on a project where I have the need to draw rectangles in an image to identify objects detected in that image, I have an example that does this but in window.forms and using the System.Drawing but in xamarin.forms I can not use it. some method to draw rectangles in an image or can you provide me with an example or documentation, if there is any way to use the System.Drawing in xamarin.forms? , thank you very much

Can someone help me with Android RecyclerViewRenderer samples?

$
0
0

In my project I have one screen which displays a list of customers. The list cell (row) consists of a number of objects including images, texts, etc. which makes it a lot of memory consuming when the list grows on.

I came to know about the introduction of RecyclerView which addresses such issues in great extents. I did searched for samples over the net, have seen sample projects in Xamarin.Android. However my requirement is to work with Xamarin forms.

Could anyone help me with supporting android renderer for RecyclerView? is there any samples available?

No constructor found for Xamarin.Forms.Platform.Android.ScrollViewRenderer::.ctor

$
0
0

On Android 4.4.2 sometimes I get:
Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ScrollViewRenderer from native handle 3870001d ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.ScrollViewRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

These seems to happen only after an update to the app.
What is interesting is that seems to be happening when we are trying to destroy a view:

at md5530bd51e982e6e7b340b73e88efe666e.ScrollViewRenderer.n_onDetachedFromWindow(Native Method) at md5530bd51e982e6e7b340b73e88efe666e.ScrollViewRenderer.onDetachedFromWindow(ScrollViewRenderer.java:80) at android.view.View.dispatchDetachedFromWindow(View.java:12787) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2706) at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4254) at android.view.ViewGroup.removeAllViews(ViewGroup.java:4186) at md5fb436084bbd4c8599b985da0bb24bd53.XFormsApplicationDroid.n_onDestroy(Native Method) at md5fb436084bbd4c8599b985da0bb24bd53.XFormsApplicationDroid.onDestroy(XFormsApplicationDroid.java:33) at android.app.Activity.performDestroy(Activity.java:5436) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1119) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3676) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3707) at android.app.ActivityThread.access$1400(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374) ...

RecyclerView on Xamarin Forms

$
0
0

Hello, i'm new to Xamarin Forms.

I wonder, is there a way to use an Android native RecyclerView control, inside Xamarin Forms ?

Maybe with a custom renderer ? Is there a working code example around ?

Breakpoint fail

$
0
0

I have a problem when I try to put a break in my code using Android emulator Visual Studio x86 Api 23 , it's no break.

This funcionality was normaly, suddenly stop breaking.

My enviroment is the follow :

VS 2017 15.8.0 Preview 1.1
Win10 Pro Build 1803
Hyper-V and Windows plataform Hypervisor enabled


How to draw on an image?

$
0
0

hello I have a .Net project and I have the need to draw rectangles on an object in an image like this in the example I give it and I have the coordinates of where I should draw the rectangles. I am something new in C # and I am having a lot of problems to draw the rectangles I was reading about how to do it with Skiasharp but I do not understand how to use the image as a liezo to draw the rectangles and to show the new image with the rectangles knows someone an easier method or will have an example of a similar project that you can use

How to add / remove item in the Masterdetailpage

$
0
0

Hi Xamarin Community

how to remove item and add new item in the slide menu of masterdetailpage upon logged in of a user something like this

by default it looks like this:

Home
Login
About

Then after successful logged in it will looks like this

Home
Logout
About
Contact us

Notification, Push Notification, Alert (which one to use?)

$
0
0

Hello,

I apologize for the very basic question that follows... but I am having trouble understanding what to use in my App. Before the question, let me explain my goal:

In order to learn how to use Xamarin Forms, I chose to write a fairly simple notification App. The function of the App is:
1) Users can register/login using an Azure database (complete)
2) Users can add friends by searching the Azure database of registered users (complete)
3) Each user has a calendar (I am using sfcalendar from Syncfusion) to which they can add tasks (not meetings, but rather, "to do" items. (complete)
4) The users can then select which of their friends to send a reminder to. (complete)
5) At the scheduled time, the users, or "friends" that have been added to the "to do" will receive a notice/reminder/alert/something...

Point 5 is where I am quite stuck. Basically, what I want is for the scheduled users to see a message pop up on their phones at the scheduled time of the "to do" item. Importantly, I would like this notification to appear even if the App is off (similar to how my email notifies me of a new email even when my email App is closed).

Sadly, I'm not really sure what to call this functionality. Is this "push notification" or just a "notification", or an alert? I'm really stuck in what to do next as I'm not even really sure the correct terminology for what I'm searching for. I do plan on using offline syncing the Azure database, so would prefer that the notice does not rely on being connected to Azure at the time of the notice. I would greatly appreciate:
1) Knowing the correct terminology for what I have described, and
2) Any general suggestions on how to achieve it.

Thanks in advance!

Dustin

TapGestureRecognizer not working properly in single click for StackLayout and Grid.

$
0
0

Hi All,

I have used TapGestureRecognizer for stacklayout and grid in my code and when click it works properly in other device except Samsung S6 galaxy. While double click it works fine.

Code Snippet:


<StackLayout.GestureRecognizers>

</StackLayout.GestureRecognizers>

Am using Xamarin Forms- 2.4.0.282 version. Could you please help me to resolve this?

Regards,

Cheran

Window.open() is not working in WKWebView

$
0
0

I am trying to open a URL in safari browser while clicking it from app's iOS WKWebView, but when I call window.open() from javascript which has no effects.

It's not hitting the decide policy in WKWebView,

[Foundation.Export("webViewecidePolicyForNavigationActionecisionHandler:")]
public void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action decisionHandler)

I have tried to override WKUIDelegate method, but it's not working. :(

Could anyone help me out?

Open mobile camera in webview

$
0
0

I'm building an application where i load website in a webview.

On website i open device camera ( take pics etc ) and its working perfectly fine on all browsers but when i load same application in xamarin.forms web view, mobile camera doesn't show up. Any idea what could be the reason ?

Regards
TA

Stacklayout GestureRecognizers is not working in UWP(Working fine in IOS and Android)

$
0
0

I have an entry surrounded by stacklayout and for the stack I added GestureRecognizers like below:

 <StackLayout>
        <Entry
            TextColor="Black"
            x:Name="phoneone"/>
            <StackLayout.GestureRecognizers>
                <TapGestureRecognizer
                        Tapped="CallingPhone1"
                        NumberOfTapsRequired="1">
                </TapGestureRecognizer>
            </StackLayout.GestureRecognizers> 
    </StackLayout>

My CallingPhone1 code:

public async void CallingPhone1(object sender,EventArgs args)
 {
        Debug.WriteLine("Enter1");
        var answer = await DisplayAlert("Alert", "Do you want to call this number?", "Yes", "No");
        if (answer)
        {
            string firstphone = phoneone.Text;
            try
            {
                PhoneDialer.Open(firstphone);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception:>>" + ex);
            }
        }
    }

When I Tap on the Entry, noting is happening in UWP. But showing The thread 0x6adc has exited with code 0 (0x0) in output box. I am using xamarin.forms 2.5.0.121934.

Thanks in advance :smile:


how to bind username in label

$
0
0

Hi Xamarin forum

how can I display my username on

Nevermind guys I all ready figure it out

How to hide item

$
0
0

Hi Xamarin Forum

how can I hide an item for example here a sample code

<ListView.ItemsSource>








</ListView.ItemsSource>

so lets say I want to hide Title 2 upon logged in and display Title 7 in place of Title 2 so how can I do it?

How to download video from webview and open in device media player xamarin forms?

$
0
0

Hi All,

I have a requirement like to download video file from webview and open the downloaded file in device media player. Could you please tell me how to solve this.

Thanks in advance.

Regards,
@Biyyapu_Suneelkumar

XF Serious memory leaks while creating new strings

$
0
0

I'm seeing some serious memory leaks from a simple string formatting operation. I noticed this due my application UI getting slower over time. I decided to create a very simple solution to isolate and test this issue by itself. It would be great to get somebody else opinion. I'm placing the basics for a XF Android project you can run with the memory profiler to see the problem. Not sure why updating a view label will cause memory leaks. Even just creating a string in the thread and not assign it to the label causes memory leaks. What am I doing wrong here? Thanks!

using System;
using Xamarin.Forms;

namespace testMemoryLeaks
{
    public class App : Application
    {
        public App()
        {
            MainPage = new RandomNumbers();
        }
    }
}

using System;

namespace testMemoryLeaks
{
    public static class Data
    {
        public static double LastRandomNumber = 0.0;

        public static void UpdateRandomNumber()
        {
            Random random = new Random();
            var next = random.NextDouble();
            LastRandomNumber = 0 + (next * 1000);
        }
    }
}

using System;
using System.Collections.Generic;
using Xamarin.Forms;
using System.Threading;

namespace testMemoryLeaks
{
    public partial class RandomNumbers : ContentPage
   {
       public Label numberLabel;
       private string someText = "";
       private bool _dataThreadEnabled = true;
        private bool _uiUpdateThreadEnabled = true;

        public RandomNumbers()
        {
            numberLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.Center,
              VerticalOptions = LayoutOptions.Center,
               TextColor = Color.White,
                Text = "Random Numbers",
                FontSize = 24,
               XAlign = TextAlignment.Center
          };

            StackLayout pageStack = new StackLayout
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Children =
                {
                    numberLabel
               }
           };
           Content = pageStack;
           StartProcessingThreads();
       }

        public void StartProcessingThreads()
        {
            // Data processing:
            ThreadPool.QueueUserWorkItem(state =>
                {
                   // Updates here
                  while (_dataThreadEnabled)
                  {
                       Data.UpdateRandomNumber();
                       Thread.Sleep(20);
                   }
               });

           // UI updating
           ThreadPool.QueueUserWorkItem(state =>
              {
                 Thread.Sleep(3000);

                    // Start loop updating values
                    while (_uiUpdateThreadEnabled)
                    {
                       // Update screen's gauges values only
                       Device.BeginInvokeOnMainThread(() =>
                           {
                              // Update label. This line is what seems to cause the memory leaks ************
                              numberLabel.Text = string.Format("Numbers {0:0.00}", Data.LastRandomNumber);
                          });
                  }
                 Thread.Sleep(25);
              });
        }
   }
}

Showing Toolbar and Tabbar on Xamarin Forms for Android

$
0
0

Good day everyone. I created a new application using Xamarin forms and it compiles without any errors . But when I run on a real device, the tool bar and tabbar doesnt show up.

Viewing all 91519 articles
Browse latest View live


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