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

How to make a grid view, picture?

$
0
0

How to make a grid view, picture?


Paypal plugin You Must Call PayPal.Forms.CrossPaypalManager.Init() before to use it

I design the interface but with database I don’t know how can I done with this idea

$
0
0
My idea is •the teacher generate random code and after that the student Enter that code to mark his attendance. and the student where mark attendance is should appear to teacher, that can be done with What

Visual Studio 2019 Run arrow does not do anything

$
0
0

Hello,

For most projects I click run arrow and it runs fine on my android device. But for some I click run arrow and it turns green again in a second. Nothing happens.

Help will be greatly appreciated.
Thanks

Problem with custom renderer height (iOS)

$
0
0

Hi all,

I have a custom renderer to add an icon to the right and/or left side of a date picker and to allow to draw a border on any side of the date picker.
This works fine as long as the icon I add is defined smaller than the size of the native controls frame.
If the icon is bigger than it seems the new size of the left/right view is not conciderered and the frame size stays the same.
I was able to fix that at least in drawing as the control is now drawn big enough.

However for some reason it seems the new size is not respected by Forms. For example if I have my custom date picker in a Stacklayouts and a button under it, then the button is very close to the date picker but there should be spacing. If I rotate from landscape to portrait, then the button even "slides" into the date picker.

My code for the custom iOS renderer looks like this:

public class CustomDatePickerIOSRenderer : DatePickerRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
        {
            base.OnElementChanged(e);
            if(Element is CustomDatePicker customPicker)
            {
                UpdateLeftIcon(customPicker);
                UpdateRightIcon(customPicker);
            }
        }

    public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            if (Element is CustomDatePicker customPicker)
            {
                ApplyBorder(customPicker);
            }
        }

    protected virtual void ApplyBorder(CustomDatePicker customPicker)
        {
            Control.BorderStyle = UITextBorderStyle.None;
            RemoveBorders();
            nfloat height = Control.Frame.Size.Height;
            if (leftView != null && leftView.Frame.Size.Height > height)
                height = leftView.Frame.Size.Height;
            if (rightView != null && rightView.Frame.Size.Height > height)
                height = rightView.Frame.Size.Height;
            Control.Frame = new CGRect(Control.Frame.X, Control.Frame.Y, Control.Frame.Width, height);
            CGColor color = Element.IsFocused ? customPicker.BorderFocusedColor.ToCGColor() : customPicker.BorderColor.ToCGColor();
            if (customPicker.Border.Left > 0)
                CreateBorderSide(0, 0, customPicker.Border.Left, Control.Frame.Size.Height,color);
            if(customPicker.Border.Right > 0)
                CreateBorderSide(Control.Frame.Size.Width-customPicker.Border.Right,0, customPicker.Border.Right, Control.Frame.Size.Height, color);
            if(customPicker.Border.Top > 0)
                CreateBorderSide(0, 0, Control.Frame.Size.Width,customPicker.Border.Top, color);
            if(customPicker.Border.Bottom > 0)
                CreateBorderSide(0, Control.Frame.Size.Height-customPicker.Border.Bottom, Control.Frame.Size.Width, customPicker.Border.Bottom, color);
        }

        protected virtual void RemoveBorders()
        {
            //remove all previously added borders again (if any)
            foreach (var layer in Control.Layer.Sublayers)
            {
                if (layer.Name != null && layer.Name.Contains("customBorder"))
                    layer.RemoveFromSuperLayer();
            }
        }

        protected virtual void CreateBorderSide(double x,double y,double width,double height,CGColor color)
        {
            CALayer borderLayer = new CALayer();
            borderLayer.Frame = new CGRect(x, y, width, height);
            borderLayer.BackgroundColor = color;
            borderLayer.Name = "customBorder";
            Control.Layer.AddSublayer(borderLayer);
        }

    private UIView leftView, rightView;

        protected virtual async void UpdateLeftIcon(CustomDatePicker customPicker)
        {
            if(customPicker.LeftIcon == null)
            {
                Control.LeftViewMode = UIKit.UITextFieldViewMode.Never;
                Control.LeftView = null;
                leftView = null;
            }
            else
            {
                leftView = await CreateSideView(customPicker.LeftIcon, customPicker.LeftIconSize);
                Control.LeftView = leftView;
                Control.LeftViewMode = UIKit.UITextFieldViewMode.Always;
            }
        }

        protected virtual async void UpdateRightIcon(CustomDatePicker customPicker)
        {
            if (customPicker.RightIcon == null)
            {
                Control.RightViewMode = UIKit.UITextFieldViewMode.Never;
                Control.RightView = null;
                rightView = null;
            }
            else
            {
                rightView = await CreateSideView(customPicker.RightIcon, customPicker.RightIconSize, false);
                Control.RightView = rightView;
                Control.RightViewMode = UIKit.UITextFieldViewMode.Always;
            }
        }

    protected virtual async Task<UIView> CreateSideView(ImageSource icon, int size, bool isLeft = true)
        {
            UIImage leftIconImage = await IosImageHelper.GetUIImageFromImageSourceAsync(icon);
            CGSize iconSize = leftIconImage.Size;
            if (size > -1)
                iconSize = new CGSize((float)size, (float)size);
            UIView paddingView = new UIView(new CGRect(0, 0, iconSize.Width + 8, iconSize.Height+8));
            UIImageView sideView = new UIImageView(new CGRect(isLeft?8:0, 4, iconSize.Width, iconSize.Height));
            sideView.Image = leftIconImage;
            paddingView.AddSubview(sideView);
            return paddingView;
        }
}

So for me it highly seems like setting Control.LeftView or Control.RightView does not affect the actual frame size of the UIControl + it does not update the Xamarin Forms view bounds.
That's why I added the manual "calculation" of the border in ApplyBorder, but as it changes the frame of the iOS native control correctly, it seems to not update the information in the Xamarin Forms Control?
I guess the solution is very simple, somehow to notify the Xamarin Forms Control to remeasure or something but I just can't figure it out right now.

Here are screenshots showing what I mean by not keeping the distance and sliding into the control.

Landscape:

Portrait:

Why am I getting back the same Bitmap even after compressed?

$
0
0

I have the following code trying to compress a bitmap and use it for uploading.

//1 Bitmap bitmap1 = BitmapFactory.DecodeByteArray(imageFileByte, 0, imageFileByte.Length);
//2 byte[] compressedData = null;
//3 using (var stream = new MemoryStream())
//4 {
//5 bitmap1.Compress(Bitmap.CompressFormat.Jpeg, 50, stream);
//6 compressedData = stream.ToArray();
//7 }

//8 //load compressed bitmap from memory
//9 using (var anotherStream = new MemoryStream(compressedData))
//10 {
//11 var compressedBitmap = BitmapFactory.DecodeStream(anotherStream);
//12 }

When I debug, bitmap1 on line 1 shows 3021330 bytes, when come to the compressedData on line 6, it did shrink to 70128 bytes. Now I want to convert again the compressedData to a bitmap again since it is a byte array but not a bitmap, when it comes to line 11, the compressedBitmap shows exactly same number of byte with the bitmap 1. How can I actually use the bitmap that has already been compressed? Is it possible to compress a bitmap and save the compressed one as a bitmap again? Thanks for any comment.

Database Options to integrate with Hybrid mobile App (Xamarin Forms)?

$
0
0

Hello Folks – I’m currently working as a Mainframe Developer. Me and my friends are planning to develop a Hybrid mobile app with Xamarin Forms. This app will do user management, allow them to make payments and plan their schedules. We are expecting 1000 users in the initial stage and go steadily thereafter. We are not sure at this moment which Database to use in the backend.

Could you please share your thoughts on which Database would be better for our use considering the user base, ease of integrating with Xamarin and minimal cost?

Android Foreground Service Preventing Memory Release?

$
0
0

I created an android application with a foreground service that is always running. Initially, when the application is completely shut down (both process and service is not running), I try to use a broadcast to wake up the service, then my application take up 36MB of memory.
Next, I open the application and the memory usage grow up to 121MB. Finally, I tried to swipe out to kill the app, OnDestroy() method in MainActivity get called and I manually called GC.Collect() within this method, however, it's still take up 109MB of memory

My foreground service is just listening to step detector sensor and store the result to 'SharedPreferences' so I believe it won't take over hundred MB. Is there anyway to release more memory when the app is swiped out by user? Thank you.


How to make the user to get sqlite db when he installs my app?

$
0
0

Hi,

I have a Xamarin.Forms application which uses SQLite DB.
The SQLite DB is on my device (Android), and the App uses it for read/write operations.

Now, if I upload the app to the market, I would like the user to get an empty SQLite db in his device.
How can I cause my app to install an Empty db in the user's phone, while he installs the app?

Thank you,
Eliran

Synchronize button disabled at the same time of form

$
0
0

Hello,

I have a problem with a button on Xamarin.Forms. The button is a synchronize button what should enable a login form. By default login form is disabled but my synchronize button is also disabled while I don't want.

I searched on this forum and I tried differents methods like

        <Button Text="Test" Command="{Binding SynchronizeButton}" IsEnabled="True"/>

instead of

        <Button Text="Test" IsEnabled="True" Command="{Binding SynchronizeButton}"/>

My Login Form in Xaml

                <Label Text="Id" IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>
                <Entry IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>
                <Label Text="Pass" IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>
                <Entry IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>

My View Model (I'm using Prism)

public class MainPageViewModel : BindableBase
{
    // Attributes
    private INavigationService _navigationService;

        private bool _activeField; (false by default)

        public bool ActiveField
        {
            get { return _activeField; }
            set
            {
                SetProperty(ref _activeField, value);
                SynchronizeButton.RaiseCanExecuteChanged();
            }
        }

    public DelegateCommand SynchronizeButton { get; private set; }


    // Constructor
        public MainPageViewModel()
        {
            SynchronizeButton = new DelegateCommand(Synchronize, CanSynchronize).ObservesProperty(() => ActiveField);
        }

    // Methods
    private bool CanSynchronize()
        {
            return ActiveField;
        }

        private async void Synchronize()
        {
            ActiveField= true;
            await _navigationService.NavigateAsync("MainPage");
        }
}

Thanks for your help

how to Implement a shell in xamarin.forms?

$
0
0

Hi, I am working on the xamarin form. My requirement is to bind navigation menus at the bottom like

once I click on the more navigation pop up or sidebar should appear like

and I want to hide the hamburger menu button
How to achieve this?

How to scuffle position of two Tabbar Shell Items programetically in run time using code behind c#.

$
0
0

How to scuffle position of two Tabbar Shell Items programetically in run time using code behind c# .

How to change text of a button in the main App from App.Android realtime?

$
0
0

Hi!

I'm receiving realtime data from platform-specific code (Firebase Realtime Database) with EventListener, but my UI is in the main App. I can't figure out how to change button text in the main App from the App.Android code realtime.

Tried Interfaces, Binding and MessagingCenter with no success.

I just want to show how many unread messages a person currently has. Like: $"You have {unreadMessagesSize} unread messages"

How do I move data files from one app to another

$
0
0

I have two apps where my "old" app are going to phase out and soon it will close down. My problem is that I have some historic data files placed where the app is installed and these data I need to move to my"new" app.

I guess that one solution is to first move all the data from the old app to an external location on the device and then - when starting up the new app - to move these files into the new app location. Problem is that it feels a bit clumsy that way. It would be nice if it's possible to just copy the data file directly from the old app to the new app some how e.g. when I start up the new app. Will that be possible .. otherwise what is the best way to handle this?

I need this for both Android and iOS :-)

Best Regards
Per

Forms + Shell + MVVM?

$
0
0

We've been developing our app for a 5years now using xamrin forms and MVVM (using FreshMVVM). We are thinking of moving to shell for new apps moving forward.

From https://nicksnettravels.builttoroam.com/mvvm-navigation/
"for commercial applications I would currently still be advocating the use of Prism or MvvmCross (rather than Shell)."

How seriously should I take this opinion?

Is there a good example to look at for Forms + Shell + MVVM?


Xamarin.forms PushNotificationPlugin, how to open a page passing data of the notification received?

$
0
0

So on my app.xaml.cs I have

CrossPushNotification.Current.OnNotificationReceived += (s, p) =>
{
//something like Navigation.PushAsync(new Page(Data from the notification));
}

How can I open 'Page' and give the data of the notification as an argoument?

Thanks to all.

Open Specific Page when click on Push Notification

$
0
0

Hi,
I am trying implement basic push notification example using Xamarin Forms with Prism MVVM, Azure & FCM.

I am receiving notification, but couldn't navigate to specific page when clicked on notification.

Trying basic functionality when app is running or in background (not closed).
It's throwing exception "PushAsync not supported globally on Android, please use a NavigationPage" at

ExploreXam.App.Current.MainPage.Navigation.PushAsync(page);

Here are MainActivity.cs and FireBaseMessagingService & App classes:

[Activity(LaunchMode = LaunchMode.SingleTask, MainLauncher = true]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    internal static readonly string CHANNEL_ID = "explore_xamarin";
    internal static readonly int NOTIFICATION_ID = 1029;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        CreateNotificationChannel();
        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }
    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        Intent = intent;
        NotificationClickedOn(intent);
    }
    private void NotificationClickedOn(Intent intent)
    {
        if (intent.Action == ExploreXamFirebaseMessagingService.ExploreXamNotification && intent.HasExtra("XamId"))
        {
            var page = new Xamarin.Forms.NavigationPage(new SpecificPage());
            Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(page);
            ExploreXam.App.Current.MainPage.Navigation.PushAsync(page);
        }
    }
}
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class ExploreXamFirebaseMessagingService : FirebaseMessagingService
{
    private const string TAG = "ExploreXamFirebaseMsgService";
    public const string ExploreXamNotification = "ExploreXamNotification";

    public override void OnMessageReceived(RemoteMessage message)
    {
        SendNotification(message);
    }

    private void SendNotification(RemoteMessage message)
    {
        var intent = new Intent(this, typeof(MainActivity));
        intent.AddFlags(ActivityFlags.SingleTop);
        intent.AddFlags(ActivityFlags.NewTask);

        intent.SetAction(ExploreXamNotification);

        intent.PutExtra("XamId", message.Data["XamId"]);

        var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
        var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);

        var notficiationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
                                                        .SetContentTitle(message.Data["title"] ?? "Explore Xam")
                                                        .SetSmallIcon(Resource.Drawable.Explore_Xam_Icon)
                                                        .SetContentText(message.Data["body"] ?? "You have a new message")
                                                        .SetAutoCancel(true)
                                                        .SetNumber(Int32.Parse(message.Data["badge"]))
                                                        .SetSound(defaultSoundUri)
                                                        .SetContentIntent(pendingIntent)
                                                        .SetSubText(message.Data["subtitle"] ?? "");

        var notificationManager = NotificationManager.FromContext(this);
        var localNotification = notficiationBuilder.Build();
        localNotification.Defaults |= NotificationDefaults.Vibrate;
        notificationManager.Notify(NOTIFICATION_ID, localNotification);
    }
}

public partial class App : PrismApplication
{
    public bool navigating;

    public App(IPlatformInitializer initializer = null, bool shallNavigate=false) : base(initializer)
    {
        navigating = shallNavigate;
    }
    protected async override void OnInitialized()
    {
        BlobCache.ApplicationName = "ExploreXam";
        InitializeComponent();
        FlowListView.Init();
        //await  NavigationService.NavigateAsync("LoginPage");
        await NavigationService.NavigateAsync("NavigationPage/LoginPage");
    }
    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        //mapping 
    }
}

Any help please....!

Tried ALL Xamarin BLE Demo Apps - None of them are working

$
0
0

It's the first time I register for a forum, because I couldn't find a solution somewhere in the internet.

I have an arduino and connected a bluetooth module. The module is a HM10 (i also have the HC08). This bluetooth module is for a bluetooth low energy (ble) connection.

Now I want to build an app for android and iOS which is able to communicate with the arduino over ble.

If I download the app "BLE Scanner" from the Play Store (guess it's written in java) I can connect to the arduino. So I have proof that my arduino setup works.

This is my concept:
1. Finding a working BLE Demo App
2. Looking in the source code and implement it in my own app.

Im searching in the internet for more than 3 months and couldn't find one single working BLE Demo app!!! Why? How in the world is this possible?

There are also many different Plugins for BLE, but none of them works. Can't someone delete this? It's just time wasting!

I tried ALL available Demo Apps in the internet for more than 3 months. Here are some links:
h-ttps://github.com/ricardoromo/BLEArduino/tree/master/BLEArduino
h-ttps://github.com/xabre/xamarin-bluetooth-le
h-ttps://github.com/aritchie/bluetoothle
h-ttps://github.com/xamarin/Monkey.BluetoothLE/tree/master/Sample%20Apps/BLE%20Explorer/BLEExplorer
h-ttps://github.com/nexussays/ble.net
very disappointed --> h-ttps://medium.com/@didourebai/integrate-and-use-the-ble-plugin-for-xamarin-edd6d8a1096d
h-ttps://acaliaro.wordpress.com/2017/02/07/connect-a-barcode-reader-to-a-xamarin-forms-app-via-bluetooth/comment-page-1/
h-ttps://greenfinch.ie/2016-07-06-bluetooth-le/

There were more links...so I'm pretty sure I don't need someone who's answer is just copying another link to a BLE demo app, because I tried them ALL!

Is there anybody who recently build a working Xamarin Forms BLE App? Or is this not possible anymore in Xamarin? I would be so so so thankful if there is someone who can send me his own source code to a real working BLE App.

Thanks in advance!

I'm new here so I couldn't post links, thats why I wrote h-ttps.

How do l ressolve System.Net.WebException Error .The Internet connection appears to be offline

Xamarin forms: Previous screen is showing behind the current screen of ios app.

$
0
0

Found the same issue here. But the solution there not help me out.

Please have a look at the following screenshot of my xamarin forms ios app.

enter image description here

My problem is the previous page is showing behind the current screen. I am using visual studio for mac and Xcode 11.2.1 for development.

How can I get the fullscreen view for pages?

Viewing all 91519 articles
Browse latest View live


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