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

Xamarin Form - Android upgrade to target v11 - Pipeline error

$
0
0

Hello all,
I am working on a Xamarin form project. For Android, I have upgrade the targetSDK to level 30 (Android 11). Everything is working fine on local. But When I run it on pipeline to get code coverage, ... it return the error as the image bellow

it worked fine before (targetSDK level 28).

Could you please give me any suggestion?


How to add swiping dots to Tabbed/Carousel page?

$
0
0

I'm wondering how to add dots indicating to swipe screens in either TabbedPage or CarouselPage like in the below image?

I tried adding images for that but they don't look natural so is there a real way for doing that?

My above workaround explanation in an example with 3 page:

I create 3 images each image has 3 dots one of them is highlighted:

First image highlighted dot is the first one.

Second image highlighted dot is the second one.

and etc.

e.IsAuthenticated is false when Login with Gmail Account using Xamarin Auth

$
0
0

private void OnAuthenticationCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
if (e.IsAuthenticated)
{
// The user is authenticated
// Extract the OAuth token
var token = new GoogleOAuthToken
{
TokenType = e.Account.Properties["token_type"],
AccessToken = e.Account.Properties["access_token"]
};

    // Do something
}
else
{
    // The user is not authenticated
}

}
I get the e.IsAuthenticated is false. Is something I wrong.
I reference this link https://timothelariviere.com/2017/09/01/authenticate-users-through-google-with-xamarin-auth/

PushModalAsync not working correctly after call back activity is fired

$
0
0
  1. Tabbed page is the root and there is "Account" content page as navigation page inside it.
  2. Account page has OnAppearing event.
  3. On a button click in Account page, a modal popup "Login" content page is pushed.
  4. In Login page, user will be authenticated and callback url is called and another modal page, Page1, is pushed. <----Issue is the OnAppearing event of Account page i.e., step 2 is called. It did not get called at step 3.

            var authResult = await WebAuthenticator.AuthenticateAsync(
                new Uri($"mywebsite.com/auth/" + scheme),
                new Uri("myapp://auth#"));
    
            await ((MainPage)Application.Current.MainPage).CurrentPage.Navigation.PushModalAsync(new Page1());
    
  5. Further another issue is when both the modals are closed using PopModalAsync in Page 1, the OnAppearing event of Account page is not called again.

        int count = Application.Current.MainPage.Navigation.ModalStack.Count;
        for (int currModal = 0; currModal < count; currModal++)
        {
            await Application.Current.MainPage.Navigation.PopModalAsync(false);
        }
    
  6. To debug the cause, pushed modal async before and after callback activity, and found that it is causing the issue.

            // OnAppearing of Account page not getting called
            await ((MainPage)Application.Current.MainPage).CurrentPage.Navigation.PushModalAsync(new Page1());
    
            var authResult = await WebAuthenticator.AuthenticateAsync(
                new Uri($"mywebsite.com/auth/" + scheme),
                new Uri("myapp://auth#"));
    
            // ISSUE: OnAppearing of Account page is called here
            await ((MainPage)Application.Current.MainPage).CurrentPage.Navigation.PushModalAsync(new Page1());
    
  7. Below is the callback activity

    [Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
    [IntentFilter(new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "myapp",
    DataHost = "auth")]
    public class WebAuthenticationCallbackActivity : WebAuthenticatorCallbackActivity
    {
    }
    

This behavior is in Android, did not test on iOS.

ListView Selected color using Application.resources

$
0
0

Is there a way to change the color of the background when an item is selected using Application.resources?

I'd like to keep things uniform throughout my application and I've been using Appliation.resources style.

Any ideas?
Thanks

Please tell i think the Device.StartTimer is not working with the Interval we have define

$
0
0

I have define the interval of 2 mins but its not give the interval of 2 mins. Their must be some issue with the Xamarin. What other option we have for the backgroundservice to call

Device.StartTimer(TimeSpan.FromMinutes(2), () =>

            {




                    MessagingCenter.Send<string>("OK", "counterValue");



                return true;

            }
            );

Device.StartTimer change speed from time to time xamarin

$
0
0

Device.StartTimer change speed from time to time xamarin. is anyone facing this problem. What is the solution of it.

Issues trying to debug on 4.0.3 device

$
0
0

Hello there!

I have a project that was working OK. I was testing on a device with Android 4.1.1, so I have set the Android configuration with that version as the minimum. Compilation SDK and target are set as 9.0. So far, so good.

But now, I need to try it on a 4.0.3 Android device and I'm having issues.
Of course, I changed minimum version, I installed Android SDK PLatform 15 from SDK Manager in Visual Studio 17, cleaned project, restart... But when I try to debug, this exception appears:

Java.Lang.NoSuchMethodError: no method with name='getLineSpacingMultiplier' signature='()F' in class Landroid/widget/TextView;

I was googling for half and an hour looking for some clue. Of course, it looks like some methods are no working because it's a very old version of Android, but I have no choice but to make it works in this device, with no chance of updating it.
The most similar answer I got was this thread:
https://forums.xamarin.com/discussion/161342/java-lang-nosuchmethoderror-no-method-with-name-getlinespacingmultiplier-signature-f-in-class
But setting Minimum version to 4.1.1 doesn't let me debug on the device (and I need to check some HW behaviour).

What can I do?
Is there a way to override all the non-existing methods like the above mentioned, if there is no way I can set the environment to test it?

Thank you!


Problem view mp4 local video

$
0
0

Hi

I have a problem to show un *.mp4 on VideoView component. My code is this:

string path = @C:\Users\Desktop\sample.mp4;

Device.BeginInvokeOnMainThread(() => { CrossMediaManager.Current.Play("file://" + path ); });

Can you help me please

CSV export in mobile directory

$
0
0
How to export CSV file xmarain activity layout.. give any sample for reference

Error in DeleteAsync call through Mobile Service Client

$
0
0

I am getting below error while I am deleting a row in a table.

Set JArray values with invalid key value: "version". Int32 array index expected.

I am fetching the all the rows from the table to a LIST initially and parsing through the same list until the value to be deleted is found and then using DeleteAsync.

Delete_Flag = "Y";
roles = await App.client.GetTable().Where(x => x.HotelId == App.HotelId).ToListAsync();
foreach (var role in roles)
{
if (Delete_Flag == "Y" && role.RoleName == Role_Picker.SelectedItem.ToString())
{
await App.client.GetTable().DeleteAsync(role);
}
}

Why Glyph property in FontImageSource doesn't bind?

$
0
0

Hi community.
I have a strange behavior with FontImageSource. I can't get property binded to Glyph.

<ContentPage.BindingContext>
        <documents:DocumentListViewModel />
    </ContentPage.BindingContext>
    <ContentPage.ToolbarItems>            
        <ToolbarItem Command="{Binding ChangeViewTypeCommand, Mode=OneWay}">
            <ToolbarItem.IconImageSource>
                <FontImageSource Glyph="{Binding ViewTypeGlyph}" Size="26" FontFamily="{x:StaticResource MaterialFontFamily}" Color="{DynamicResource PrimaryColor}"/>
            </ToolbarItem.IconImageSource>
        </ToolbarItem>
    </ContentPage.ToolbarItems>

public string ViewTypeGlyph
        {
            get
            {
                switch (this.ViewType)
                {
                    case ViewType.SmallRows:
                        return MaterialDesignIcons.ViewAgendaOutline;
                    case ViewType.BigRows:
                        return MaterialDesignIcons.CropSquare;
                    case ViewType.Grid:
                        return MaterialDesignIcons.ViewGridOutline;
                }
                return MaterialDesignIcons.ViewAgendaOutline;
            }
        }

I put a break point on the get block and it does not raise.

What am I missing?

Note: setting Glyph to static property works as well

<FontImageSource Glyph="{x:Static icons:MaterialDesignIcons.ViewAgendaOutline}" Size="26" FontFamily="{x:StaticResource MaterialFontFamily}" Color="{DynamicResource PrimaryColor}"/>

How to select multiple images from gallery from both android and iOS device?

$
0
0

Hello,
I am working on xamarin.forms app. I am creating the app for android and iOS. I need to open the gallery and select multiple images from gallery of devices. How I can do this in xamarin.forms that can work for both android and iOS?

Regards,
Anand Dubey

Create a simple Foreground service for Xamarin Form project

$
0
0

Hello,

First, sorry for this question, there is a lot of subjects for this point but, the sample project not working anymore, or it's only xamarin.android, or I am to dumb I don't know ..

I am pretty new to Xamarin, but I readded all the Microsoft docs about Services, locale notification, foreground service.

But I am not able to create a running app.

To start, I just want to create an app that count seconds between start and stop service, so, I will like to know if you have a simple project starting and stopping a foreground service. As simple as it's can be, my goal it's to understand how it's working

I will continue to work on my side to achieve this goal, creating a new project, restart from nothing and hope I will success, as it seem to be a simple thing ..

Thanks for your help and your time !

Edit : I created a simple project, still not working ...

In cross code

MainPage.xaml

`private void startClicked(object sender, EventArgs e)
{
try
{
//Start service

            DependencyService.Get<IAndroidService>().StartService();
        }
        catch
        {
            return;
        }

        startBtn.IsEnabled = false;
        stopBtn.IsEnabled = true;
    }

    private void stopClicked(object sender, EventArgs e)
    {
        try
        {
            //Stop service

            DependencyService.Get<IAndroidService>().StopService();
        }
        catch
        {
            return;
        }

        startBtn.IsEnabled = true;
        stopBtn.IsEnabled = false;
    }`

IAndroidService.cs

`public interface IAndroidService
{
void StartService();

    void StopService();
}`

INotification
public interface INotification { Notification ReturnNotif(); }

In Android code

AndroidServiceHelper.cs

`internal class AndroidServiceHelper : IAndroidService
{
private static Context context = global::Android.App.Application.Context;

    public void StartService()
    {
        var intent = new Intent(context, typeof(simpleService));

        if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
        {
            context.StartForegroundService(intent);
        }
        else
        {
            context.StartService(intent);
        }
    }

    public void StopService()
    {
        var intent = new Intent(context, typeof(simpleService));
        context.StopService(intent);
    }
}`

in NotificationHelper.cs

` internal class NotificationHelper : INotification
{
private static string foregroundChannelId = "1003";
private static Context context = global::Android.App.Application.Context;

    public Notification ReturnNotif()
    {
        // Building intent
        var intent = new Intent(context, typeof(MainActivity));
        intent.AddFlags(ActivityFlags.SingleTop);
        intent.PutExtra("Simple project", "Message from simple project");

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

        var notifBuilder = new NotificationCompat.Builder(context, foregroundChannelId)
            .SetContentTitle("Simple project")
            .SetContentText("Main text for simple project")
            .SetSmallIcon(Resource.Drawable.LogoBenne)
            .SetOngoing(true)
            .SetContentIntent(pendingIntent);

        // Building channel if API verion is 26 or above
        if (global::Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.O)
        {
            NotificationChannel notificationChannel = new NotificationChannel(foregroundChannelId, "TitleSimpleProject", NotificationImportance.High);
            notificationChannel.Importance = NotificationImportance.High;
            notificationChannel.EnableLights(true);
            notificationChannel.EnableVibration(true);
            notificationChannel.SetShowBadge(true);
            notificationChannel.SetVibrationPattern(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 });

            var notifManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
            if (notifManager != null)
            {
                notifBuilder.SetChannelId(foregroundChannelId);
                notifManager.CreateNotificationChannel(notificationChannel);
            }
        }

        return notifBuilder.Build();
    }
}`

in simpleService.cs

`public class simpleService : Service
{

    private int number = 0;
    public override IBinder OnBind(Intent intent)
    {
        return null;
    }

    public const int ServiceRunningNotifID = 9000;

    public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
    {
        Notification notif = DependencyService.Get<INotification>().ReturnNotif();
        StartForeground(ServiceRunningNotifID, notif);

        count(ref number);

        return StartCommandResult.Sticky;
    }

    public override void OnDestroy()
    {
        base.OnDestroy();
    }

    public override bool StopService(Intent name)
    {
        return base.StopService(name);
    }

    private void count(ref int number)
    {
        number++;
    }
}`

Thanks a lot !

on Shell Tabbar 5 icons how to change on the middle of icon size and color then the other 4 icon?

$
0
0

ı have android shell renderer that I could change all icon size

public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
bottomView.ItemIconSize = 80;
}

Total are 5 icons on Tabbar..I would like to change only middle of icon size larger and color on shellrenderer for anroid and ios?

thanks for solution...


Xamarin Forms: How to add dragging event for labels? - Word Search Game

$
0
0

I am trying to implement a word search game for my project. I have created the word search letterbox using the grid and label (using this blog). Each letterbox has some words and that words are listed under the letterbox. I need to select the word hidden in the letterbox by dragging the labels. When start dragging the background color changed to orange. If the dragged word is in the words list, change the background color to green. Also, I need to capture the total, right and wrong attempts.

Please watch this video for getting a clear idea. I have also added a sample project here for the reference. I need to do the below things:

  1. Dragging event for labels inside the grid.

  2. Change the background color to orange(when starts dragging) and green(when the word is in the list).

  3. A tickmark for found words.

  4. Capture the total attempts, wrong attempts, and correct attempts.

Xamarin Forms: How to generate a word search puzzle matrix?

$
0
0

I am trying to implement a word search game on my xamarin forms application. Only words are getting when I call my service. With these words how can I generate a letter matrix?

I am expecting a 10x10 letter matrix like below screenshot:

enter image description here

The words are hidden inside this matrix-like below screenshot (Stephen, Nicholas, Ambrose, Juan Diego, Xavier, Sylvester I):

enter image description here

The words can put in any format: the right to left, left to right, top to bottom, bottom to top or in crossway.

Is there any tool for this feature? I need to select the letters as per screenshot 2 for playing this game.

How to add admob ads in Xamarin Forms

$
0
0
Hi I need some help I've been trying to set this ads for month. Please help

Xamarin Forms: BaseContentPage and BackButtonBehavior Binding not working (Shell)

$
0
0

Hey guys,

I created my own BaseContentPage and created a BindableProperty for a custom BackButtonBehavior.
My goal is to change the standard backbutton icon and allow a custom BackButtonBehavior with own Commands.

My BaseContentPage looks like that:

    public class BaseContentPage : ContentPage
    {
        public static readonly BindableProperty CustomBackButtonBehaviorProperty =
            BindableProperty.Create(nameof(CustomBackButtonBehavior), typeof(BackButtonBehavior), typeof(BaseContentPage),
                                            null, defaultBindingMode: BindingMode.Default
                                            ,propertyChanged: OnBackButonBehaviorPropertyChanged);


        public BackButtonBehavior CustomBackButtonBehavior
        {
            get
            {
                if (GetValue(CustomBackButtonBehaviorProperty) == null)
                    return CreateDefaultBackButtonBehavior();
                else
                    return (BackButtonBehavior)GetValue(CustomBackButtonBehaviorProperty);
            }
            set { this.SetValue(CustomBackButtonBehaviorProperty, value); }
        }

        public BaseContentPage()
        {
            //Shell.SetBackButtonBehavior(this, CustomBackButtonBehavior);
        }

        private BackButtonBehavior CreateDefaultBackButtonBehavior()
        {
            Application.Current.Resources.TryGetValue("FontAwesomeSolid", out var fontAwesomeSolid);

            var behavior = new BackButtonBehavior()
            {
                Command = new Command(async () =>
                {
                    await Shell.Current.GoToAsync("..");
                }),
                IconOverride = new FontImageSource()
                {
                    FontFamily = ((OnPlatform<string>)fontAwesomeSolid).Platforms.FirstOrDefault(p => p.Platform[0] == Device.RuntimePlatform).Value.ToString(),
                    Glyph = Controls.FontAwesomeSolid.IconConstants.ChessPawn,
                    Size = 22,
                    Color = Color.White
                },
            };

            return behavior;
        }

        static void OnBackButonBehaviorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {

        }
    }

I use it for a new Xaml Page, which looks like that:

<?xml version="1.0" encoding="utf-8" ?>
<d:BaseContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                   xmlns:d="clr-namespace:IncomingDocumentApp.Controls"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="xxxx.Views.NewItemPage.NewItemPage"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
             ios:Page.UseSafeArea="true"
             Title="New Item"
             Visual="Material">

than i tried to set the BackButtonBehavior:

   <d:BaseContentPage.CustomBackButtonBehavior>
        <BackButtonBehavior Command="{Binding GoBackCommand}"
                            IsEnabled="True"/>
    </d:BaseContentPage.CustomBackButtonBehavior>

However, it the CustomBackButtonBehaviorProperty is never called.
The Binding is defined in the codebehind of the NewItemPage right after the InitializeComponent() call.

Any help would be appreciated!

snoova

MVU, ReactiveUI and MVVM in .Net Maui

$
0
0

The maui team is integrating MVVM,ReactiveUI and MVU in the framework. I know that ReactiveUI is also a MVVM framework. But still it is different than the Xamarin.Forms MVVM. Does ReactiveExtensios can be useful with MVU architecture.
What are the pros and cons of using each one of the architecture?
I expect someone with knowledge of app architectures to throw light on the matter. This will help existing as well as new developers in choosing the right architecture before they start coding.

Viewing all 91519 articles
Browse latest View live


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