Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all 204402 articles
Browse latest View live

How to inspect incoming data from a SignalR connection?

$
0
0

I am creating a chat app and when I send a message it calls an event to send it to all clients, a broadcast. But I don't want to display the message back to the client that originally sent it. I cant think of an elegant way of doing it. All the ways I thought of it are bulky and stupid. Every message has a bool, Incoming. I am using Azure to host the SignalR hub.

Right now I have this to add the incoming messages to the ObservableCollection, "Messages"
_chatService.OnMessageReceived += (sender, message) => Messages.Add(message);

I wanted to assign a random ID number to each message getting sent. And if the message incoming has a matching ID# then I don't display it. But the only way I thought of being able to do that is to store the message in a temp ObservableCollection. then check the most recent addition and check its ID. But that seems really inefficient/stupid...

Also I thought of no displaying the message locally and only display it when it comes back from the server. But this has the same problem. Every message coming from the server would have the Incoming bool equal True.

Also I am only broadcasting to all clients because that is more simple and they way the tutorial I followed did it. Maybe this can all be fixed by only sending messages from the 1 person that is part of the chat (or all the people from a group chat)

Thanks


Facebook Native Login

$
0
0

Hello developers,

which is the method correct the native implementation in Xamarin forms?

any tutorial? any alternative different the native?

Regards.

Login using Facebook SDK

$
0
0

Hello guys ,
I am trying to have the login feature using Facebook SDK . The current component that we have is kind of outdated (two months old) and is not compatible with the newer versions Xamarin.Forms or its dependencies. I tried to follow this blog about it.
I have tried to make a BindingLibrary for the native Facebook SDK , but you know how it goes with that .
So my question is have you guys managed to do that recently ? have you managed to make the binding library working fine ?
Has anyone access to the Binding Library project of this component ?
Anyone would like to help in the binding library ?

Authenticate and share image on facebook.

$
0
0

I want to sharing the post on facebook by getting authenticated from my app.I am working on forms but tried to get this done by using DI.
I am doing something like this in myproject.iOS

public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);

// 1. Create the service
var facebook = new FacebookService {
    ClientId = "*********",
    RedirectUrl = new System.Uri ("http://com.abc.com")
};

// 2. Create an item to share
var item = new Item { Text = "Xamarin.Social is the bomb.com." };
item.Links.Add (new Uri ("http://github.com/xamarin/xamarin.social"));

// 3. Present the UI on iOS
var shareController = facebook.GetShareUI (item, result => {
    // result lets you know if the user shared the item or canceled
    DismissViewController (true, null);
});
PresentViewController (shareController, true, null);

}

but i am not able to see anything happening on the app side.Please help me out with this.

Integrate Facebook login in Xamarin.Forms PCl

$
0
0

I want to Integrate Facebook login in my Project that is using Xamarin.Forms PCl.

is it possible to integrate Facbook login in xamarin.form for Windows 8 App and others platform too?

Xamarin.Forms - Facebook Login : Native login page (Android)

$
0
0

Hello,
Initially i tried to use this library https://github.com/jsauve/OAuthTwoDemo.XForms/ but the problem was that the Library opened a WebView with mobile Facebook Login, and the user was forced to insert every time facebook username and password.

Instead with my solution my app open native facebook login page and if can't find Facebook App installed on device, it open a WebView.

Android Project Reference:

Xamarin Project Reference:

Xamarin.Forms Project:
Create Custom Button

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

namespace MyApp.CustomControls
{
    public class FacebookLoginButton : Button
    {

    }
}

Create Login Page (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:customcontrols="clr-namespace:MyApp.CustomControls;assembly=MyApp"
             x:Class="MyApp.LoginPage" BackgroundColor="White">
        <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="15">
                <customcontrols:FacebookLoginButton Text="Login With Facebook" VerticalOptions="Start"
                HorizontalOptions="FillAndExpand"></customcontrols:FacebookLoginButton>
        </StackLayout>
</ContentPage>

Xamarin.Android Project:
Create Custom Button Renderer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Acr.XamForms.UserDialogs;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MyApp.CustomControls;
using MyApp.Droid.Utils;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(FacebookLoginButton), typeof(FacebookLoginButtonRenderer))]
namespace MyApp.Droid.Utils
{
    public class FacebookLoginButtonRenderer : ButtonRenderer
    {
        public Xamarin.Forms.Button formsButton;
        private readonly IUserDialogService _dialogService;

        public FacebookLoginButtonRenderer()
            : base()
        {
            this._dialogService = DependencyService.Get<IUserDialogService>();
        }
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                formsButton = e.NewElement;
            }
            if (this.Control != null)
            {
                global::Android.Widget.Button button = this.Control;
                button.Click += button_Click;
            }
        }

        void button_Click(object sender, EventArgs e)
        {
            var activity = this.Context as Activity;
            var intent = new Intent(activity, typeof(LoginActivity));

            Forms.Context.StartActivity(intent);
            formsButton.Navigation.PopModalAsync();
        }
    }
}

Create LoginActivity

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Acr.XamForms.UserDialogs;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MyApp.Services;
using Xamarin.Facebook;
using Xamarin.Forms;
//IMPORTANT You MUST define "app_id" in Strings.xml
[assembly: MetaData("com.facebook.sdk.ApplicationId", Value = "@string/app_id")]
namespace MyApp.Droid
{
    [Activity(Label = "LoginActivity")]
    public class LoginActivity : Activity, Session.IStatusCallback, Request.IGraphUserCallback
    {
        private readonly IUserDialogService _dialogService;
        public LoginActivity()
            : base()
        {
            this._dialogService = DependencyService.Get<IUserDialogService>();
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            OpenFacebookSession();
        }

        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            // Relay the result to our FB Session
            Session.ActiveSession.OnActivityResult(this, requestCode, (int)resultCode, data);
        }

        public void Call(Session session, SessionState state, Java.Lang.Exception exception)
        {
            // Make a request for 'Me' information about the current user
            if (session.IsOpened)
                Request.ExecuteMeRequestAsync(session, this);
        }

        public async void OnCompleted(Xamarin.Facebook.Model.IGraphUser user, Response response)
        {
            // 'Me' request callback
            if (user != null) {

                string fb_id = user.Id;
                string fb_email = user.InnerJSONObject.Get("email").ToString();
                string fb_firstName = user.FirstName;
                string fb_lastName = user.LastName;
                string message = String.Format("{0} {1}. FacebookID: {2}. Email: {3}", fb_firstName, fb_lastName, fb_id, fb_email);
                this._dialogService.Alert(message);
                Console.WriteLine(message);
            }
            else
            {
                string message = "Problem during Facebook Login!");
                this._dialogService.Alert(message);
                Console.WriteLine(message);
            }
            OnBackPressed();
        }

        public void OpenFacebookSession()
        {
            // Ask for username and password
            Xamarin.Facebook.Session.OpenRequest op = new Session.OpenRequest(this);
            //op.SetLoginBehavior(SessionLoginBehavior.SsoWithFallback);
            op.SetCallback(this);

            List<String> permissions = new List<String>();
            //permissions.Add("publish_stream");
            //permissions.Add("user_likes");
            permissions.Add("email");
            //permissions.Add("user_birthday");
            //permissions.Add("publish_actions");
            //permissions.Add("share_item");
            //permissions.Add("user_friends");
            //permissions.Add("user_groups");

            op.SetPermissions(permissions);

            Session session2 = new Xamarin.Facebook.Session.Builder(this).Build();
            Session.ActiveSession = session2;
            session2.OpenForPublish(op);
        }
    }
}

That's all!

Please contact me if you have suggestion!

Esteban Lombardo
.NET Developer
Logica S.r.l.

Facebook Share

$
0
0

Hi,

I need to implement FB share in my app (Xamarin Forms PCL) and I tryed really a lot of plugin and working for many days with no success.
Can you please share your experience on which is the best plugin to reach the goal and how to use it?

I need to implement bot on Android and iOS

Thank you a lot for your help!

My share post using Facebook SDK not public


How to import Facebook-SDK for Xamarin Forms

$
0
0

Hello,
I'm currently developing an Xamarin Forms app that needs to authenticate users, using Facebook.
However, I'm having a hard time figuring out the steps to import and use the Facebook-SDK in my project.

My question is: Where do I import the following code to my Xamarin forms project and how can i do it?

I've already added the Facebook SDK using Gradle extention for Visual Studio 2017.
Nonetheless, I cant figure out point 6

Import the Facebook SDK

To use the Facebook SDK in a project, add it as a build dependency and import the Facebook SDK packages.

Important: If you're adding the SDK to an existing project, start at step 3.

  1. Go to Android Studio | New Project | Minimum SDK.
  2. Select API 15: Android 4.0.3 (IceCreamSandwich) or higher and create your new project.
  3. In your project, open your_app | Gradle Scripts | build.gradle (Project) and add the following repository to the buildscript { repositories {}} section to >download the SDK from the Maven Central Repository:
  • mavenCentral()
  1. In your project, open your_app | Gradle Scripts | build.gradle (Module: app) and add the following compile statement to the dependencies{} section to >compile the latest version of the SDK:
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
  2. Build your project.
  3. Add the following statements to import the Facebook SDK packages:
  • import com.facebook.FacebookSdk;
  • import com.facebook.appevents.AppEventsLogger;

Thanks

Circle button in Xamarin.Forms. Super easy way

$
0
0

Guys, there is super easy way to create Circle/Round buttons in XF.
What you need to do is to use BorderRadius, WidthRequest and HeightRequest (you must use all these properties)
Make in mind simple formula:
WidthRequest = BorderRadius * 2
HeightRequest = BorderRadius * 2

or another way:
BorderRadius = WidthRequest / 2
BorderRadius = HeightRequest / 2

So finally, if your WidthRequest and HeightRequest both are equals 40, then your BorderRadius will be 20.
See the attached screens for this simple and nice hack :)

simple text:

font awesome:

Stable Channel: Xamarin.iOS 11.6, 15.5.1 Release for iOS 11.2, tvOS 11.2, watchOS 4.2 SDK bindings

VS Mac Ios Scrollview

$
0
0

I can do the hard stuff but this agrevating me. Get an Ios app view to scroll. I have a sample solution from another forum member , it builds and runs in the sim fine. I cant get my stupid hello world scroll to move. Simp single view using the Storybook. Have the controller, it is set for freeform and the view is extended. added the a scrollview from tool box added views and button. It builds show the top of the view but wont scroll down. What am i missing???? information is vague or deprecated. Thanx for reading and any feedback.

ContextActions bar appears while tapping listview item to move to another page

$
0
0

I have an issue with ContextAction using within a listview.

I have 2 pages A and B
A has a listview
B is a page with the details of the item in list on page A (but B could be any other page, the problem is the same)
The listview in A has a ContextAction
When I tap an item i move to next page and the ContextAction bar appears.
It seems like two events are generated, but I have no idea where it comes from. I have implemented the same pattern on another page and it works.

<ListView
            x:Name="TransactionProductsListView"
            ItemsSource="{Binding TransactionProducts}"
            ItemTapped="ProductItemTapped">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout
                            Orientation="Horizontal"
                            Padding="0,0,0,0"
                            Margin="0">
                            <BoxView
                                VerticalOptions="Center"
                                WidthRequest="3"
                                HeightRequest="40"
                                Color="CornflowerBlue"/>
                            <StackLayout>
                                <StackLayout.GestureRecognizers>
                                    <TapGestureRecognizer
                                        Tapped="ProductBoxTapped"
                                        CommandParameter="TestCheck"
                                        NumberOfTapsRequired="1"/>
                                </StackLayout.GestureRecognizers>
                                <BoxView
                                    VerticalOptions="CenterAndExpand"
                                    WidthRequest="15"
                                    HeightRequest="15"
                                    Color="{Binding InCart, Mode=OneWay, Converter={StaticResource BoolToColorConverter}}"/>
                            </StackLayout>
                            <Label
                                HorizontalOptions="StartAndExpand"
                                VerticalOptions="Center"
                                Text="{Binding Product}"
                                Margin="2,0,0,0">
                            </Label>
                            <Entry
                                HorizontalOptions="End"
                                VerticalOptions="Center"
                                HorizontalTextAlignment="End"
                                MinimumWidthRequest="70"
                                Keyboard="Numeric"
                                Placeholder="      0.00"
                                Completed="PriceEntered_Completed"
                                Text="{Binding Price, Mode=TwoWay, Converter={StaticResource PriceToStringConverter}}"/>
                            <Label
                                HorizontalOptions="End"
                                VerticalOptions="Center"
                                Text="zł"
                                Margin="0,0,10,0"/>
                        </StackLayout>
                        <ViewCell.ContextActions>
                            <MenuItem
                                Text="Delete"
                                Clicked="DeleteTransactionProductContextAction_Clicked"
                                CommandParameter="{Binding .}"
                                IsDestructive="True"/>
                        </ViewCell.ContextActions>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

in the code behind
private void ProductItemTapped(object sender, ItemTappedEventArgs e)
{
ListView listView = sender as ListView;
if (listView.SelectedItem == null)
return;
listView.SelectedItem = null;
TransactionProductModel model = e.Item as TransactionProductModel;
ViewModel.ItemTappedCommand.Execute(model);
}

The command function
public async void ItemTapped(TransactionProductModel model)
{
await _pageService.PushAsync(new TransactionProductDetailPage(model));
}

Here is the code of the page where it works correctly

<ListView.ItemTemplate>



Do you have an Idea what is happening?
If you need any other information about my issue I will provide it.

Thank you

Visual Studio editing using XCode and Constraints

$
0
0

I am developing a series of videos on Scrollview (see xamaringatordev.com) in IOS and as such start my project in Visual Studio then switch to my Mac and use XCode to do the actual design. I started by learning to do this in Xcode and things look great as I develop a vertically scrolling example using Autolayout. This was based on articles like https://raywenderlich.com/159481/uiscrollview-tutorial-getting-started . then I opened my VS project on a shared drive with my Mac and did the same steps in XCode after launching it from VS on Mac (surely there is a better way to do this). However when I save the Xcode changes on Mac and VS synchronizes the changes VS makes a mess of the constraints. I then reduced the test to simply do:
1. create Scrollview and pin to (0,0,0,0) so it work on all display views
2. add a content view that will be the scroll able content here same constraints but height is fixed 1000

as I said in Xcode the designer is happy with the constraints but here is result in VS

the reason is that VS has lost all constraints for the content view except the height as shown below:

little disappointing as we at the mercy of the Xcoode interchange work well as the VS designer is very challenged. I will have the complete video on my blog in couple of days so one can see the whole process.

Color properties in storyboard doesn't work properly.

$
0
0

Hi all, I'm using Visual Studio 2017 and developing an application for IOS devices. I have two buttons that has different background color property on the view. When I selected one of them, property window always show that the background color is red. I'm changing that property but when I selected the other one the background color property stays as the previous one. Is there a way to solve this?

Versions for Mac and PC:
On Mac: Visual Studio Community 7.3(build 799), Xamarin.IOS 11.6.1.2
On PC: Visual Studio Community 15.5.1, Xamarin.IOS 11.6.1.2


CGImage.ScreenImage(id,rect); is returning a 1x1 image

$
0
0

Hi there,

I'm trying to capture the screen into a CGImage object.
The code I'm converting originally called

cgImage = CGDisplayCreateImage(_displayId);

I don't see a direct replacement for that in Xamarin, so instead I'm trying:

CGRect rect = CGDisplay.GetBounds(_displayId);
cgImage = CGImage.ScreenImage(_displayId, rect);

I assume the _displayId is correct because I get a rect back 1680x1050
It's retrieved using

CGRect rect = CGDisplay.GetBounds(_displayId);

Is there some initializer call I'm missing? Or some alternative call I can make to get a CGImage back of the screen?

Alternatively, can anyone show me what the signature would look like to DllImport this one?

CG_EXTERN CGImageRef __nullable CGDisplayCreateImage(CGDirectDisplayID displayID)?

how to save multiple Entry.text or Label.Text for reassign to an other Entry.Text

$
0
0

Hi all,
habitually for this step i use in C# two List<> and a double loop.

I add Label.Text in a List:

List mytext = new List();
mytext.Add(Label.Text);

I group my Controls in a List:

List myEntry = new List();
myEntry.Add(Entry);

And i reassign a string with double loop:

foreach (var S in myEntry)
{
foreach (var e in mytext)
{
S.Text = e
}
}

but it does not work in Xamarin.Forms
I create dynamiclly the Entry, i save a TextValue for each Entry, I modify a number of Entry and i reinject a Value.Text.

Can you helpme please ?

Thx

.NET Standard 1.3 Compatibility Issue with .NET framework 4.6

$
0
0

I'm getting error when I changed the .NET Standard from 1.0 to 1.3 of the class library projects.

targets '.NETStandard,Version=v1.3'. It cannot be referenced by a project that targets '.NETPortable,Version=v4.5,Profile=Profile111'

Portable Project:
TargetFrameworkVersion : v4.5
TargetFrameworkProfile: Profile111

Class Library Project:
TargetFramework: netstandard1.3
PackageTargetFallback: $(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8

I have tried to change the framework in the project file to v4.6 but I got another issue with the framework profile 111.

I'm using Visual Studio 2017 and I'm new to Xamarin Froms.

Is it possible to target these projects or I'm doing it wrong?

Thanks!

Animation on xamarin forms using Lottie dont work!

$
0
0

Hi,
anyone use the Lottie nugget to play animations on xamarin forms.
I tested a simple example that dont run, just appear on android emulator a blank window.

I install the Lottie nugets.

Here is my xaml 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:forms="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"

         x:Class="Example.Forms.MainPage">

    <forms:AnimationView

            x:Name="AnimationView"

            Animation="LottieLogo1.json"

            Loop="True"

            AutoPlay="True"

            VerticalOptions="FillAndExpand"

            HorizontalOptions="FillAndExpand" />

I put the file "LottieLogo1.json" on Resources folder of the Droid Project.

Thanks

How to use NSRange / NSDictionary in attributed text, e.g. Link in a string

$
0
0

Hello All, I came across the following S.O. question that shows the answer I am looking in Objective C. I am trying to convert, but this is the first time I am using NSRange and NSDictionary. Any help?

stackoverflow.com/questions/1256887/create-tap-able-links-in-the-nsattributedstring-of-a-uilabel

  NSMutableAttributedString attributedString = new NSMutableAttributedString("String with a link");

  NSRange linkRange = new NSRange(14,4); // for the word "link" in the string above

  NSDictionary linkAttributes = new NSDictionary("NSForegroundColorAttributeName", UIColor.FromRGBA(0.05f, 0.4f, 0.65f, 1.0f), "NSUnderlineStyleAttributeName", "NSUnderlineStyleSingle");
  attributedString.SetAttributes(linkAttributes, linkRange);

  label.AttributedText = attributedString;

Any help would be appreciated.

Viewing all 204402 articles
Browse latest View live


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