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

Custom Bindable picker selectedItem not firing

$
0
0

I have a custom BindablePicker which inherits from picker, having copied some code in a previous post. However I am finding that when an item is selected, my property is not being updated.

BINDABLEPICKER
public class BindablePicker : Picker
{
#region Fields

        //Bindable property for the items source
        public static readonly BindableProperty ItemsSourceProperty =
            BindableProperty.Create<BindablePicker, IEnumerable>(p => p.ItemsSource, null, propertyChanged: OnItemsSourcePropertyChanged);

        //Bindable property for the selected item
        //public static readonly BindableProperty SelectedItemProperty =
        //  BindableProperty.Create<BindablePicker, object>(p => p.SelectedItem, null, BindingMode.TwoWay, propertyChanged: OnSelectedItemPropertyChanged);

        public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create("SelectedItem", typeof(object), typeof(BindablePicker), null, BindingMode.TwoWay, null, propertyChanged:OnSelectedItemPropertyChanged);

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the items source.
        /// </summary>
        /// <value>
        /// The items source.
        /// </value>
        public IEnumerable ItemsSource
        {
            get { return (IEnumerable)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }

        /// <summary>
        /// Gets or sets the selected item.
        /// </summary>
        /// <value>
        /// The selected item.
        /// </value>
        public object SelectedItem
        {
            get { return GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Called when [items source property changed].
        /// </summary>
        /// <param name="bindable">The bindable.</param>
        /// <param name="value">The value.</param>
        /// <param name="newValue">The new value.</param>
        private static void OnItemsSourcePropertyChanged(BindableObject bindable, IEnumerable value, IEnumerable newValue)
        {
            var picker = (BindablePicker)bindable;
            var notifyCollection = newValue as INotifyCollectionChanged;
            if (notifyCollection != null)
            {
                notifyCollection.CollectionChanged += (sender, args) =>
                {
                    if (args.NewItems != null)
                    {
                        foreach (var newItem in args.NewItems)
                        {
                            picker.Items.Add((newItem ?? "").ToString());
                        }
                    }
                    if (args.OldItems != null)
                    {
                        foreach (var oldItem in args.OldItems)
                        {
                            picker.Items.Remove((oldItem ?? "").ToString());
                        }
                    }
                };
            }

            if (newValue == null)
                return;

            picker.Items.Clear();

            foreach (var item in newValue)
                picker.Items.Add((item ?? "").ToString());
        }

        /// <summary>
        /// Called when [selected item property changed].
        /// </summary>
        /// <param name="bindable">The bindable.</param>
        /// <param name="value">The value.</param>
        /// <param name="newValue">The new value.</param>
        private static void OnSelectedItemPropertyChanged(BindableObject bindable, object value, object newValue)
        {
            var picker = (BindablePicker)bindable;
            if (picker.ItemsSource != null)
                picker.SelectedIndex = picker.ItemsSource.IndexOf(picker.SelectedItem);
        }



        #endregion
    }
}

VIEW
<local:BindablePicker Title="Relationship" ItemsSource="{Binding PersonLinkTypes}" SelectedItem="{Binding SelectedLinkType}"/>

VIEWMODEL

            private string _selectedLinkType;
                public string SelectedLinkType 
                { 
                    get
                    {
                        return _selectedLinkType;
                    }
                    set
                    {
                        _selectedLinkType = value;
                    }
                }

        private IEnumerable<string> _PersonLinkTypes;
        public IEnumerable<string> PersonLinkTypes 
        { 
            get
            {
                return _PersonLinkTypes;
            }
            set
            {
                _PersonLinkTypes = value;
                OnPropertyChanged("PersonLinkTypes");
            }
        }

How to set selected tab in tabbed page - xamarin forms

$
0
0

Hi Everyone,

I am new to xamarin, and i am working with tabbed page with Android and Ios.

There is a requirement to add a tab between the tabbed pages, and upon clinking it need to do some functionalities and get back to home tab.

I am able to do the functionalities and set the home tab back using the following code.

protected override void OnCurrentPageChanged()
{
base.OnCurrentPageChanged();
if (this.CurrentPage != null && this.CurrentPage.ClassId == "some id")
{
...some codes
CurrentPage = Children[0];
}
}

It is loading the home page content, but the selected tab (Highlighting) was not updated.

Can anyone help me out ?

Xamarin.Android remove compiler warnings

$
0
0

Hi,

I'm getting a lot of warnings when compiling Xamarin.Android project, for example:

Severity Code Description Project File Line Suppression State
Warning Skipping F1Mobile.Droid.Resource.Style.TextAppearance_StatusBar_EventContent_Time. Please check that your Nuget Package versions are compatible. F1Mobile.Droid

Severity Code Description Project File Line Suppression State
Warning Skipping F1Mobile.Droid.Resource.Style.TextAppearance_AppCompat_Notification_Time_Media. Please check that your Nuget Package versions are compatible. F1Mobile.Droid

Does anyone know how to remove them?

thanks.

Continuously pushing location data to server periodically even when the app is in background

$
0
0

HI,

I am working on an app to send the location details periodically to the server when the app is open in the foreground or in the background.
Location sent date and time must be displayed(or updated) on the screen.

I have tried Wakelock, Timer, and Foreground service.
I am able to get the location periodically but Android is not allowing to access the internet when is the phone is locked.

Any help on how to achieve this?

How to use Windows like filesystem action on Mac?

$
0
0

Hello,

Here is my issue: I have an application using an old mono version (4.4.1) on an old ide (Xamarin 6.0.1) and some Windows internal calls such as FindNext or GetFileStats. These are InternalCall methods that I need to run my application.

I have updated everything to their last version, so I am now using Visual Studio for Mac 2017 and Mono 5.18.0.249 (with their associated XamMac.dll).
When I start the application, it says that FindNext or FindFirst method is not found anymore (Missing method exception) and that my mono build is sort of broken.

So how do I replace these methods?
I need methods that give me the stats of a file (if it's hidden, etc), ones that get the next file in line in a ptr, or the first in a folder, etc.
Such as found on Windows .Net.

If anyone knows I am all ears :smile:

If I was not clear, tell me, I will try to explain the situation better.

Xamarin form : How to select multiple files form filepicker

$
0
0

i have developed to pick file form mobile, but need to pickup multpple file here is my code

try
{
FileData fileData = await CrossFilePicker.Current.PickFile();
if (fileData == null)
return; // user canceled file picking

        string fileName = fileData.FileName;
        string contents = System.Text.Encoding.UTF8.GetString(fileData.DataArray);

        System.Console.WriteLine("File name chosen: " + fileName);
        System.Console.WriteLine("File data: " + contents);
    }
    catch (Exception ex)
    {
        System.Console.WriteLine("Exception choosing file: " + ex.ToString());
    }

need to know how i can select multiple files

Xamarin Forms Application.Current Properties Backup on user Google Drive account

$
0
0

I want to store my Application.Current.Properties to user's Google Drive Account as backup via Google Drive REST API v3. And Sync functionality from App to Drive and vice a versa.

I have searched and found very little info about it. But unable to take start as I am a newbie in using the user's Cloud storage.

So can anyone guide me how to achieve this? No such documentation or video tutorial found to do it from scratch. I need help.
Thanks in advance.

Xamarin Forms ios - Continuous task to work for hours even app in the background

$
0
0

My requirement is to send the location of the device to the rest api continuously for every 30 seconds.
I have used UIApplication.SharedApplication.BeginBackgroundTask to make it work even the app went to the background, but IOS is suspending the app after 3 minutes.
Is it possible to continuously allow the app to work in the background for hours?


Connect to MSSQL from Android via vpn

$
0
0

Hi, I have a question about connecting to a database that runs on a server computer. When I access this database, I need to connect to a VPN and then use the connection string to connect to this database.
I use Visual Studio 2017, Xamarin, GenyMotion Version 3.0.0

ConnectionString
str = "Data Source = 172.16.172.12; Initial Catalog = SerBet; User ID = Project; Password = XX";
SqlConnection conn = new SqlConnection ();
conn.ConnectionString = str;
conn.Open ();

When I run the emulator, everything works the way it works. When I run my app on my phone, the connection will not take place.
catch (SqlException ex) = Snix_Connect (provider: SNI_PN7, error: 40-SNI_ERROR_40)

can someone give me an advice what could be the diference between emulator and real run from the android device?

FirebaseInstanceIdService is deprecated and OnNewToken() not working

$
0
0

I want to implement OnNewToken() method from FirebaseMessagingService in my Xamarin Android project that uses Firebase Cloud Messaging since FirebaseInstanceIdService and OnTokenRefreshed() are deprecated.

I tried this

[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MessagingService : FirebaseMessagingService
{
    const string TAG = "MyFirebaseMsgService";
    public override void OnNewToken(string token)
    {
        Log.Debug(TAG, "Refreshed token: " + token);
        SendRegistrationToServer(token);
    }

    public void SendRegistrationToServer(string token)
    {
        ...
    }

}

But my OnNewToken() is not hit. What am I doing wroing. Do i need to include anything in my Android manifest file? I cannot find any documents specific to Xamarin Android about this update. Please help. Thank you so much.

Android Pie Not Getting Current Location in App Background Sleep Mode

$
0
0

Hi Friends,

I want to get current location, when app went into sleep mode or Background.Currently i am using > Plugin.Geolocator.CrossGeolocator.Current DLL in App OnSleep() , But Its Working Till Android 8.1 but Android Pie Not updating current Location Values.. How to Achieve in Android Pie?

My Code:
var minute = TimeSpan.FromSeconds(30);
Device.StartTimer(minute, () =>
 { 
await Task.Run(async () =>
 {
TimeSpan t = TimeSpan.FromSeconds(10);
 var locator = Plugin.Geolocator.CrossGeolocator.Current;
locator.DesiredAccuracy = 5;
   var position = await locator.GetPositionAsync(timeout: t); 
//API Method
 });
 });

When NUnit 3 Will be Supported, What is the future of Xamarin.UITest Vs. Other Automation Tools?

$
0
0

I have two questions in single quote.

  1. When NUnit 3 will be supported to Xamarin.UITests?
  2. What is the Future of Xamarin.UITest? As there is no improvement and interesting releases for Xamarin.UITest against other Mobile automation tools in the market (lets say Appium). Here NUnit 3 is also not being supported by Xamarin. We have already started and reached 60% completion of Mobile Automation using Xamarin.UITest, so now question is what is the future (plan) of Xamarin.UITest?

Google Tag Manager & Google Analytics on Xamarin Forms using UWP

$
0
0

We have a website where Xamarin Forms is deployed on the Universal Windows Platform. Can we deploy Google Tag Manager & Google Analytics in this instance and if so how?

Error in xamarin.google.ios.mobileads NuGet package when running on actual device!

$
0
0

I am using the newest version of xamarin.google.ios.mobileads - it works on my simulator, but as soon as I try deploying it to my device (XS max), it starts up and shortly after i crashes - with this error message :

Launched application 'dk.netcoders.iphone.quizmo' on 'Tonys iPhone XS Max' with pid 12858
dyld: Library not loaded: @rpath/PersonalizedAdConsent.framework/PersonalizedAdConsent
  Referenced from: /var/containers/Bundle/Application/52F4754D-505E-4633-AC54-63CB9CA4A86C/quiz.app/quiz
  Reason: no suitable image found.  Did find:
    /private/var/containers/Bundle/Application/52F4754D-505E-4633-AC54-63CB9CA4A86C/quiz.app/Frameworks/PersonalizedAdConsent.framework/PersonalizedAdConsent: code signature in (/private/var/containers/Bundle/Application/52F4754D-505E-4633-AC54-63CB9CA4A86C/quiz.app/Frameworks/PersonalizedAdConsent.framework/PersonalizedAdConsent) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)
Application 'dk.netcoders.iphone.quizmo' terminated.

How to change version of NuGet package ? (vs 4 mac)

$
0
0

I am used to using Visual Studio for Windows, but now when using Visual Studio for Mac I cannot seem to figure out how to change the installed version of a NuGet package ?

Only way is to remove NuGet, search for it again and add it with a new version.

Isnt there an easier way than this ?


Event of button is not getting fired in absolute layout

$
0
0

Hello All,
I am facing an strange behavior in Xamarin.forms.

When i m writting below xaml code it's working fine as expected but the same thing i m trying to achieve dynamically from code behind event for button is not getting fired.
XAML code:

<AbsoluteLayout> <Button x:Name="firstChild" Text="First Child"></Button> <AbsoluteLayout Padding="70"> <Label Text="inner child"></Label> </AbsoluteLayout> </AbsoluteLayout>

Below is my .cs code which is trying to achieve the same thing but event is not getting fired.

public partial class TestPage : ContentPage
{

    MR.Gestures.AbsoluteLayout mainLayout = new MR.Gestures.AbsoluteLayout ();
    Button firstChild = new Button {
        Text = "First Child",
        TextColor = Color.White,
        BackgroundColor = Color.Red 
    };

    MR.Gestures.AbsoluteLayout innerLayout = new MR.Gestures.AbsoluteLayout {Padding=70};
    Label innerLabel=new Label{
        Text="inner child",
        TextColor=Color.Red
    };

    public TestPage ()
    {
        InitializeComponent ();
        firstChild.Clicked += btnclick;
        mainLayout.Children.Add (firstChild);
        innerLayout .Children.Add (innerLabel);
        mainLayout.Children.Add (innerLayout );


        this.Content = mainLayout;
    }
    void btnclick(object sender,EventArgs args)
    {
        DisplayAlert ("Hello", "Hello World", "OK");
    }
}

Getting different instances while resolving from container

$
0
0

I have a specific platform service which is being registered using a platform initializer

 public class AndroidInitializer : IPlatformInitializer
    {
        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterInstance<IBlueToothService>(new BlueToothService_Android());
        }
    }

As you see I am registering an instance as I want it to be the same instance.
My main page VM get this service injected in its constructor:

public MainPageViewModel(INavigationService navigationService, IBlueToothService btService)
           : base(navigationService)
        {
             RefreshBlueTooothDevicesCommand = new DelegateCommand(RefreshBlueToothExecuted, RefreshBlueToothCanExecute);
            _blueToothService = btService;
            _blueToothService.DeviceAdded += BlueToothServiceDeviceAdded;
            _blueToothService.ScanFinished += () => ToggleRunningState();
        }

I am using this service also in a broadcast receiver:

 public override void OnReceive(Context context, Intent intent)
        {            
           IBlueToothService service = Xamarin.Forms.DependencyService.Get<IBlueToothService>();
            string action = intent.Action;
            if (action == BluetoothDevice.ActionFound)
            {
                BluetoothDevice newDevice = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
                service.AddDevice(new Models.BluetoothDevice(newDevice.Name, newDevice.Address));
            }
            if(action == BluetoothAdapter.ActionDiscoveryFinished)
            {
                service.RaiseScanFinishedEvent();
            }
        }

I am not getting the same instance. but 2 different ones. I am pretty sure that each one of them resolves them from a different container but I cant figure our how to point all of them to the same one.

Thanks.

Why building an application in release mode marks warnings about “not found” files?

$
0
0

My app seems to be built fine in Debug mode, yet in Release mode I get 21 warnings about "no debug symbols file was found".

As I understood, debug mode uses some files that release mode doesn't need in order to run, I assume that the missing files are these ones. Maybe it's a problem with Xamarin or with VS?


Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.v7.AppCompat.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Java.Interop.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Arch.Core.Common.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Arch.Lifecycle.Common.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Arch.Lifecycle.Runtime.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Animated.Vector.Drawable.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Annotations.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Compat.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Core.UI.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Core.Utils.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Design.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Fragment.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Media.Compat.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Transition.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.v4.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.v7.RecyclerView.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Vector.Drawable.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Base.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Basement.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Maps.dll but no debug symbols file was found. 0
Warning Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Tasks.dll but no debug symbols file was found. 0


  1. What are those files? What those warnings mean?

  2. What can I do about it?

  3. Can those warnings cause any further damage?

I already tried:

  1. Deleting those files from obj\Release\81\android/assets.

  2. Cleaning the solution and the whole project.

Picker SelectedItem not persistent

$
0
0

Hi devs !

In a TabbedPage, on the first tab, I have a Picker. When I select a value from the Picker, change tab and return to the first one, the Picker value is reset.

How can I make it persistent ?

Thanks.

Label text clipping bottom or top in xamarin forms uwp

$
0
0

While using the label the bottom or top of the text is cutting slightly. Even I have given enough height it's still there. You could see in the following
screenshot the word is slightly cut in the bottom.

Have anyone faced this issue, please help. Thanks in advance.

Viewing all 204402 articles
Browse latest View live


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