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

CollectionView IsGrouped="True" null exception on Android

$
0
0

Hi!

I have a problem when in a CollectionView I assign the value True to attribute IsGrouped.

In UWP it works fine, but in Android it fails

What should I do?

I already have the CollectionView Flags configured in my MainActivity

<CollectionView ItemSizingStrategy="MeasureAllItems" 
                    ItemsSource="{Binding Modules}"
                    IsGrouped="True"
                    SelectionMode="Single">
    • • •
</CollectionView>

Thanks for your attention!!


ViewCell Selected Background Color in iOS 13

$
0
0

Prior to iOS 13, you could set a background color in a ViewCell, and change that background color to another color when the cell is pressed. The color change would start on the press down and reset on release. The press feedback no longer works in iOS 13 if you use a cell background color other than transparent.

I need to use a cell background color to get the style I want in my app. Does anyone know a way to use a cell background color and get a touch effect in iOS 13 in a ListView? I've tried a number of approaches, but they all just capture the press release, not the press down. I did manage a workaround for cells in a TableView, but I still need help for cells in a ListView. Thanks!

Does Xamarin.Forms require the Google Play Services to be present on Android ...

$
0
0

... and if so is there a way around that?

I am asking since quite a large part of our Apps users is on Huawai phones and due to the current embargo Huawei will be discarding the Google Play Services and everything related with upcoming phones.

Since our Apps are all written in Xamarin.Forms we are now faced to investigate if we can support running our Apps on Huawei phones that do not have Google Play Services.

Sorry if that question has already been asked, but searching through Google did not provide me with satisfying results.

Best regards.

Custom Properties in Custom Control not Displayed in Previewer

$
0
0

I have a custom control with 2 custom properties that I want to see in the Xamarin.Forms Previewer in Visual Studio 2019. Here is the code for the custom control:

using System;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace ScorePad
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    [DesignTimeVisible(true)]
    public partial class CheckBox : StackLayout
    {
        public event EventHandler<CheckedChangedEventArgs> CheckedChanged = (sender, e) => { };
        public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(String), typeof(CheckBox), string.Empty);
        public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create("IsChecked", typeof(bool), typeof(CheckBox), false);

        public string Text
        {
            get => (string)GetValue(CheckBox.TextProperty);
            set => SetValue(CheckBox.TextProperty, value);
        }
        public bool IsChecked
        {
            get => (bool)GetValue(CheckBox.IsCheckedProperty);
            set => SetValue(CheckBox.IsCheckedProperty, value);
        }

        public CheckBox()
        {
            InitializeComponent();
            this.chkCheckBox.CheckedChanged += this.ChkCheckBox_CheckedChanged;
        }

        private void ChkCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e) { this.CheckedChanged(this, e); }
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<StackLayout x:Class="ScorePad.CheckBox" x:Name="CheckBoxRoot"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:d="http://xamarin.com/schemas/2014/forms/design"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" BackgroundColor="Black" Style="{StaticResource CheckBoxStackLayoutStyle}">
    <CheckBox x:Name="chkCheckBox" Style="{StaticResource CheckBoxBoxStyle}" BindingContext="{x:Reference CheckBoxRoot}" IsChecked="{Binding IsChecked}"/>
    <Label Style="{StaticResource CheckBoxLabelStyle}" BindingContext="{x:Reference CheckBoxRoot}" Text="{Binding Text}"/>
</StackLayout>

Notice that the 2 custom properties (Text & IsChecked) are databound to the controls in the custom control. However, they do not appear in the Previewer, although they do appear when I debug the app. This is my first custom control, so maybe I'm just forgetting something simple, so any help would be appreciated. Thanks.

PRISM Navigation

$
0
0

I need to go to the next page from my current page(WelcomeView). I use next syntax.

await NavigationService.NavigateAsync(new Uri("app:///WelcomeView/RegistrationView", UriKind.Absolute));

But it doesn't work. I still on my WelcomeView page. But if i write /WelcomeView/RegistrationView/LoginView app jump over the RegistrationView to the LoginView. How can I fix it? What am I doing wrong?

Open Source Zebra RFID SDK for Xamarin Forms

$
0
0

Hello,

Zebra Technologies have SDKs for their RFID Scanners on platforms including native iOS, native Android and Xamarin.Android however not for Xamarin.iOS or Xamarin.Forms.

We are currently building a Xamarin.Forms app which critically requires the use of the RFID Scanner (RFD8500 model to be precise) on iOS. Our understanding is that this can be achieved by creating an iOS Binding Library for Zebra's existing Objective-C iOS SDK. I have personally attempted to bind this library through two methods, one being the classic iOS Binding method and two, creating a local C# Nuget Package for consumption. Due to lack of Objective-C experience, both attempts were unsuccessful.

What we would like to know is:

  • Is what we are trying to do even possible? (i.e would a binding library be enough to get the RFID scanners to work with a .forms app)
  • If so, what is the scale of effort?
  • As we lack the technical skills for it, would anybody be up for getting involved in this Open Source? (doing the actual work)

I think this would be a great project to do as over the last few months, I have found that a LOT of developers/companies have suffered from this same issue.

Thank you
Ridhwan

Flip An Image

$
0
0

Has anyone figured out a way to flip in Image in Xamarin Forms? Not rotate it - I use that for something else - but to flip it on the vertical axis? It does not appear that Xamarin supports the ScaleTransform I could use to do this w/ MSFT.

thanks!

Open Source Zebra RFID SDK for Xamarin Forms

$
0
0

Hello,

Zebra Technologies have SDKs for their RFID Scanners on platforms including native iOS, native Android and Xamarin.Android however not for Xamarin.iOS or Xamarin.Forms.

We are currently building a Xamarin.Forms app which critically requires the use of the RFID Scanner (RFD8500 model to be precise) on iOS. Our understanding is that this can be achieved by creating an iOS Binding Library for Zebra's existing Objective-C iOS SDK. I have personally attempted to bind this library through two methods, one being the classic iOS Binding method and two, creating a local C# Nuget Package for consumption. Due to lack of Objective-C experience, both attempts were unsuccessful.

What we would like to know is:

  • Is what we are trying to do even possible? (i.e would a binding library be enough to get the RFID scanners to work with a .forms app)
  • If so, what is the scale of effort?
  • As we lack the technical skills for it, would anybody be up for getting involved in this Open Source? (doing the actual work)

I think this would be a great project to do as over the last few months, I have found that a LOT of developers/companies have suffered from this same issue.

Thank you
Ridhwan


Xamarin Forms: Push notification is not receiving to ios device

$
0
0

I have done the following things:

  1. Created a project in FCM console and added ios project into it.
  2. Downloaded the GoogleService-Info.plist and added it to the xamarin forms ios project directory and set the build action as Bundlesource.
  3. On Info.plist enabled remote notification background mode.
  4. Added FirebaseAppDelegateProxyEnabled in the app’s Info.plist file and set it to No.
  5. Created a provisioning profile and distribution certificate and installed it into the keychain access. Also, mapped these certificates in the project options.
  6. Uploaded .p12 certificate in FCM console.
  7. Added codes for handling push notification in AppDelegate.cs.

My Code:

    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App("",""));
            RequestPushPermissionsAsync();
            _launchoptions = options;
            return base.FinishedLaunching(app, options);
        }
        NSDictionary _launchoptions;
        public override void OnActivated(UIApplication uiApplication)
        {
            base.OnActivated(uiApplication);
            if (_launchoptions != null && _launchoptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
            {
                var notfication = _launchoptions[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                PresentNotification(notfication);
            }
            _launchoptions = null;
        }

        async Task RequestPushPermissionsAsync()
        {
            var requestResult = await UNUserNotificationCenter.Current.RequestAuthorizationAsync(
                 UNAuthorizationOptions.Alert
                | UNAuthorizationOptions.Badge
                | UNAuthorizationOptions.Sound);

            bool approved = requestResult.Item1;
            NSError error = requestResult.Item2;
            if (error == null)
            {
                if (!approved)
                {
                    Console.Write("Permission to receive notification was not granted");
                    return;
                }

                var currentSettings = await UNUserNotificationCenter.Current.GetNotificationSettingsAsync();
                if (currentSettings.AuthorizationStatus != UNAuthorizationStatus.Authorized)
                {
                    Console.WriteLine("Permissions were requested in the past but have been revoked (-Settings  app)");
                    return;
                }
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }
            else
            {
                Console.Write($"Error requesting permissions: {error}.");
            }
        }

        public async override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            if (deviceToken == null)
            {
                return;
            }
            Console.WriteLine($"Token received: {deviceToken}");
            await SendRegistrationTokenToMainPRoject(deviceToken);
        }

        async Task SendRegistrationTokenToMainPRoject(NSData deviceToken)
        {
            MessagingCenter.Send<object, string>(this, "fcmtoken", deviceToken.ToString());
        }

        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            Console.WriteLine($"Failed to register for remote notifications: {error.Description}");
        }

        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo,
            Action<UIBackgroundFetchResult> completionHandler)
        {
            PresentNotification(userInfo);
            completionHandler(UIBackgroundFetchResult.NoData);
            try
            {
                UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
                var message = (aps[new NSString("webContentList")] as NSString).ToString();
                LoadApplication(new App("", message));
            }
            catch (Exception ex)
            {
                //LogInfo.ReportErrorInfo(ex.Message, ex.StackTrace, "AppDelegate-DidReceiveRemoteNotification");
            }
        }

        void PresentNotification(NSDictionary userInfo)
        {
            NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;

            var msg = string.Empty;

            if (aps.ContainsKey(new NSString("alert")))
            {
                msg = (aps[new NSString("alert")] as NSString).ToString();
            }
            if (string.IsNullOrEmpty(msg))
            {
                msg = "(unable to parse)";
            }
            MessagingCenter.Send<object, string>(this, App.NotificationReceivedKey, msg);
        }
    }

I am not using any NuGet packages in ios part. When running the project into a device, the FCM token generating part is working and I can see the fcm token on the VS console. I tried to send a test notification to a device from postman but getting InvalidRegistration error.

Postman Response

{
    "multicast_id": 8754155136812875313,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "InvalidRegistration"
        }
    ]
}

Postman Body

 {
    "to" : "d20ad003 7473bfba 85dffc33 1534decf b4b886f1 c738878f fd7f2c60 d9dabc36",
 "collapse_key" : "type_a",
 "data" : {
     "body" : "Body of Your Notification in Data",
     "title": "Title of Your Notification in Title",
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
 },
 "notification" : {
     "body" : "Body of Your Notification",
     "title": "Title of Your Notification",
     "sound": "default",
     "content_available" : true
 }
}

I have completed the android part implementation and notifications are receiving when push from the postman. But getting InvalidRegistration error on postman and not receiving any notification in my ios device.

Anyone suggest a solution for this issue.

Thanks in advance.

App Icons iOS 13

$
0
0

Hello,

can anybody tell me how to provide App Icons for iOS 13?
I can'T upload my App because Xcode complaints that the App Icons are missing?

Google Assistant Integration with Xamarin Form

$
0
0

Hi,

Could any one tried google assistant implementation with xamarin form.
It should be great if you have any samples.

Thanks in advance

Masked Entry Behaviour (Field Level Masking/Validation)

$
0
0

We've created a behavior here that will be useful for a lot of people:
https://github.com/MelbourneDeveloper/Adapt.Presentation/blob/master/Adapt.Presentation.Standard/Adapt/Presentation/Behaviours/EntryPatternMatchValidationBehaviour.cs

The Entry control seems to lack a fair bit of basic functionality. One of those lacking features is the ability to specify a pattern matching Mask to stop the user from entering silly input. This behavior allows you to specify a Mask that will allow you to validate things like numbers at the field level. The Mask is specified in RegEx so it's very flexible.

Here is a XAML example that forces the user to only input a valid decimal number with two decimal places. I.e. non-numeric characters can not be entered:

                            <Entry Grid.Row="2" Text="{Binding Qty, Mode=TwoWay}" VerticalOptions="Center" Keyboard="Numeric">
                                <Entry.Behaviors>
                                    <behaviours:EntryPatternMatchValidationBehaviour Mask="^\d+(?:\.\d{0,2})?$" Default="0" />
                                </Entry.Behaviors>
                            </Entry>

To see the sample, clone this repo which is a Xamarin library with a bunch of stuff that doesn't come out of the box in Xamarin. Try the Validation tab for this sample.
https://github.com/MelbourneDeveloper/Adapt.Presentation.git

Changing View from public to internal with XAML (x:ClassModifier)

$
0
0

Hi,

I have a question regarding the internal XAML Class Modifier.

I tried to set it to x:ClassModifier="internal" or x:ClassModifier="NotPublic"
But by doing so I get the compiler error CS0262 (Partial declarations of 'type' have conflicting accessibility modifiers)
because I have already changed my codebehind file to internal also.

By looking at the *.g.cs File I see that the generated code is public partial class … so I think it is not respecting
that x:ClassModifier Keyword or I am doing something wrong here ?

Opening pdf on android device error: file exposed beyond app through intent.getdata()

$
0
0

In my application I download the pdf from an API and store the file on the local file system. Then I try to open the pdf file with the built in viewer of the user. The next message appear:
*.pdf file exposed beyond app through intent.getdata().

 public static void OpenPDF(Context context, string filePath)
        {            
            //Open it up
            Android.Net.Uri pdfPath = Android.Net.Uri.FromFile(new Java.IO.File(filePath));
            Intent intent = new Intent(Intent.ActionView);
            intent.SetDataAndType(pdfPath, "application/pdf");
            intent.SetFlags(ActivityFlags.GrantReadUriPermission);
            intent.SetFlags(ActivityFlags.NewTask);
            intent.SetFlags(ActivityFlags.ClearWhenTaskReset);
            context.StartActivity(intent);
        }

Am i missing something?

Is it possible to detect a long tap on a CollectionView item?

$
0
0

I started using the new CollectionView, but I can't figure out how to detect a long tap (and execute a command) on an item in the CollectionView.
So far I've been using the Syncfusion SfListView which comes with a HoldCommand, but i'd like to start using the CollectionView and I need to have that same feature.

Thanks in advance if someone can provide a simple example.


Best way to implement an ObservableCollection whose objects are accessible from multiple views?

$
0
0

I am fairly new to Xamarin. I'm currently working on a project and am trying to use best MVVM practices in building it. I've successfully implemented the MVVM pattern for my login page and I have a pretty good grasp on that, but it is a little more straight forward than what I'm trying to do now.

Once you log in you're brought to a TabbedPage. The TabbedPage contains two ContentPages, one with a ListView. My goal is to create an ObservableCollection which can be accessed by both of the ContentPages in the TabbedPage but I'm not sure where the correct place to create this ObservableCollection would be.

Should I create a ViewModel for the TabbedPage and have the ObservableList live there and have the ViewModels for the two ContentPages access that ViewModel? Should I create the ObservableList in the ViewModel of the first ContentPage with the ListView and have the second ContentPage reference that ViewModel?

I've tried looking for resources to understand this particular scenario but I haven't been able to find any that discuss multiple views referencing the same ObservableList. I'd be very grateful for either an explanation on the best way to do this, or a link to a resource that would explain or exemplify this. Thanks!

I should also note that I currently have the ObservableList living in the code behind for the ContentPage with the ListView. I know this is not where it should be but I just wanted to make sure I could get the ListView working with an ObservableList and I am now looking to move it to where it should be.

POS printing issue xamarin forms

$
0
0

I have connected Bluetooth Mobile printer and wanted to design the receipt. I am new to xamarin. Is there a way to design it like crystal reports or other way. Please give me some suggestions. I wanted to create a receipt like this.

I tried like this to break into lines. How can we give spaces

public ICommand PrintCommand => new Command(async () =>
{
conn = DependencyService.Get<iSQLite>().SQLiteConnectionGetConnection();
PrintMessage = string.Empty;

        PrintMessage += "\n" + "Test";
        PrintMessage += "\n" + "No.200,Main Road";
        PrintMessage +=  "\n" + "City";
        PrintMessage += "\n" + "000-45615544";
        await _blueToothService.Print(SelectedDevice, PrintMessage);
    });`

But this showing like this.Telephone number is coming first.

000-45615544
Test
No.200,Main Road
City

Error unexpected element found in

$
0
0

I have a problem, migrate my project code VS 2017 to VS 2019.
And I have an error in the Android Manifest of a style.

True way to stop MVVM operations after page close.

$
0
0

When i back from a page,i want to cancel all threads of the page like playing sounds ..(working in viewmodel ) , what should i do ?

Issue with Android 10

$
0
0

I've been experiencing this issue with my current app after setting target framework to android:targetSdkVersion="29". I've double checked that this happens with a sample application for easier debugging. This is replicated with the WorkingWithNavigation sample app.

Anytime a page is pushed or popped off the navigation stack this error occurs. I'm assuming this has to do with the animation of the navigation.
Any ideas or thoughts on how to fix this issue?

11-09 11:57:51.138 W/avigation.Droi(18447): Accessing hidden field Landroid/view/animation/Animation;->mListener:Landroid/view/animation/Animation$AnimationListener; (greylist-max-p, reflection, denied)
11-09 11:57:51.139 E/FragmentManager(18447): No field with the name mListener is found in Animation class
11-09 11:57:51.139 E/FragmentManager(18447): java.lang.NoSuchFieldException: No field mListener in class Landroid/view/animation/Animation; (declaration of 'android.view.animation.Animation' appears in /system/framework/framework.jar!classes3.dex)
11-09 11:57:51.139 E/FragmentManager(18447): at java.lang.Class.getDeclaredField(Native Method)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.getAnimationListener(FragmentManager.java:1301)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.setHWLayerAnimListenerIfAlpha(FragmentManager.java:1283)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.completeShowHideFragment(FragmentManager.java:1746)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1822)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
11-09 11:57:51.139 E/FragmentManager(18447): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
11-09 11:57:51.139 E/FragmentManager(18447): at android.os.Handler.handleCallback(Handler.java:883)
11-09 11:57:51.139 E/FragmentManager(18447): at android.os.Handler.dispatchMessage(Handler.java:100)
11-09 11:57:51.139 E/FragmentManager(18447): at android.os.Looper.loop(Looper.java:214)
11-09 11:57:51.139 E/FragmentManager(18447): at android.app.ActivityThread.main(ActivityThread.java:7356)
11-09 11:57:51.139 E/FragmentManager(18447): at java.lang.reflect.Method.invoke(Native Method)
11-09 11:57:51.139 E/FragmentManager(18447): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
11-09 11:57:51.139 E/FragmentManager(18447): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Viewing all 91519 articles
Browse latest View live