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

How to handle different Android screen sizes

$
0
0

I do not know where to start. I started customizing my app to a 4.5 inch display. But now I have to state that some layouts such as that of a ListView are shown shortened on larger displays.

I also need an adaptation to the sizes 4.7 -6.0 inches.

What can I do to display different layouts on different screen sizes?


Identity Providers with Xamarin Forms and Azure

$
0
0

Hi guys,

I'm a bit confused about Identity Providers in a project I'm doing with Xamarin Forms.

I configured Facebook as an IP with Azure Mobile Apps following this page
https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-how-to-configure-facebook-authentication

It works, but my doubt is, how can I use the MobileServiceUser result of the authentication process to, for example, post to Facebook or get personal information from Facebook. Is this possible?

Thanks, I'm new in Xamarin and all this mobile world.

Post to facebook on behalf of the user using access token in xamarin.forms

$
0
0

I build Xamarin.Forms App using this tutorial:

docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started and I choose .NET back end.

and also implement authentication using this: docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-users

while choosing Facebook as my authentication provider.

My question is, how can I post on facebook on behalf of the user using the access token that I got from the "MobileServiceUser"? I saw that it has a property called "MobileServiceAuthenticationToken" and I tried to use that token as a access token and create a FacebookClient using the Facebook sdk and that code:

FacebookClient fb = new FacebookClient(user.MobileServiceAuthenticationToken); string myMessage = "Hello";

fb.PostTaskAsync("me/feed", new { message = myMessage });

but no luck , can anyone help and see my mistake ?

Renderer - how to access properties from parent?

$
0
0

Hi,

I have a PageRenderer class. In the parent one I have a property. What I want is to set this property from the Renderer class.
One option might be, making this prop. static and access it by using
ParentClass.prop = value;

But that would not ensure the instance from the right parent class will be used, right?
Not I would go for a solution like:

using the OnElementChanged method to get an the parent page.

protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Page> e)
        {
        _myPrivatePage = (NameOfParentClass)e.NewElement;
            base.OnElementChanged(e);
...
    }

Is that the way to go?
Unforunately I can't access the property by using _mypPrivatePage.property, after using the above method.

DatePicker: Disable holidays

$
0
0

Hey Guys,

I need to customize the datepicker calendar so that it could have a bindableproperty to hold a list of holidays which should be disabled in the datepicker. It will need a custom renderer, but i don't know exactly the required code to implement this in iOS and Android projects? Any help is much appreciated

xamarin.auth with Amazon as a provider

$
0
0

I am using the Xamarin.Auth in Xamarin.Forms using a shared project (not a PCL) and trying to get the amazon presenter to work properly. I believe I have it all down, except the presenter is not closing. I am guessing that it is due to my redirect_uri being incorrect. However, I cannot find what the format that they are sending back. Google wants the client ID returned backwards, others have a URL, etc. When I used it with my Amazon Echo Skill (Audubon Bird Calls) it redirects to some weird login for "layla" so apparently they may not be adhering to any standards....oh yeah, there are not any!

I was hoping to use the Cognito service from Amazon, but ran into similar issues.

Thanks for the guidance!

Problem with building Android Wear

$
0
0

I am trying to create an Android Wear project with xamarin, but I cannot get my project to run.
I updated all the packages to the latest version

My android wear project is a standalone app so I set the minimum SDK version to 23.

These are the most important packages that I am using in my android wear project:
Xamarin.GooglePlayServices.Wearable: v42.1021.1
Xamarin.Android.Wear: v2.0.1.1
Xamarin.Android.Support.Wear: v26.1.0.1
Xamarin.Android.Support.v4: v26.1.0.1

I always get the following exception at starting my project:
<br /> 1>obj\Debug\android\src\mono\android\support\wear\widget\SwipeDismissLayout_OnDismissedListenerImplementor.java:8: error: package android.support.wear.widget.SwipeDismissLayout does not exist<br /> 1> android.support.wear.widget.SwipeDismissLayout.OnDismissedListener<br /> 1> ^<br /> 1>obj\Debug\android\src\mono\android\support\wear\widget\SwipeDismissLayout_OnPreSwipeListenerImplementor.java:8: error: package android.support.wear.widget.SwipeDismissLayout does not exist<br /> 1> android.support.wear.widget.SwipeDismissLayout.OnPreSwipeListener<br /> 1> ^<br /> 1>obj\Debug\android\src\mono\android\support\wear\widget\SwipeDismissLayout_OnSwipeProgressChangedListenerImplementor.java:8: error: package android.support.wear.widget.SwipeDismissLayout does not exist<br /> 1> android.support.wear.widget.SwipeDismissLayout.OnSwipeProgressChangedListener<br /> 1> ^<br /> 1>Note: Some input files use or override a deprecated API.<br /> 1>Note: Recompile with -Xlint:deprecation for details.<br /> 1>Note: Some input files use unchecked or unsafe operations.<br /> 1>Note: Recompile with -Xlint:unchecked for details.<br /> 1>3 errors<br /> 1> error: package android.support.wear.widget.SwipeDismissLayout does not exist<br /> 1> android.support.wear.widget.SwipeDismissLayout.OnDismissedListener<br /> 1><br /> 1> error: package android.support.wear.widget.SwipeDismissLayout does not exist<br /> 1> android.support.wear.widget.SwipeDismissLayout.OnPreSwipeListener<br /> 1><br /> 1> error: package android.support.wear.widget.SwipeDismissLayout does not exist<br /> 1> android.support.wear.widget.SwipeDismissLayout.OnSwipeProgressChangedListener<br /> 1><br /> 1>Done building project "NormalWearTest.csproj" -- FAILED.<br /> 1>Build FAILED.<br />

This is the file where the problem is located (SwipeDismissLayout_OnDismissedListenerImplementor.java):
<br /> package mono.android.support.wear.widget;</p> <p>public class SwipeDismissLayout_OnDismissedListenerImplementor<br /> extends java.lang.Object<br /> implements<br /> mono.android.IGCUserPeer,<br /> android.support.wear.widget.SwipeDismissLayout.OnDismissedListener<br /> {<br /> /** @hide */<br /> public static final String __md_methods;<br /> static {<br /> __md_methods = <br /> "";<br /> mono.android.Runtime.register ("Android.Support.Wear.Widget.SwipeDismissLayout+IOnDismissedListenerImplementor, Xamarin.Android.Support.Wear, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", SwipeDismissLayout_OnDismissedListenerImplementor.class, __md_methods);<br /> }</p> <pre><code>public SwipeDismissLayout_OnDismissedListenerImplementor () { super (); if (getClass () == SwipeDismissLayout_OnDismissedListenerImplementor.class) mono.android.TypeManager.Activate ("Android.Support.Wear.Widget.SwipeDismissLayout+IOnDismissedListenerImplementor, Xamarin.Android.Support.Wear, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "", this, new java.lang.Object[] { }); } private java.util.ArrayList refList; public void monodroidAddReference (java.lang.Object obj) { if (refList == null) refList = new java.util.ArrayList (); refList.add (obj); } public void monodroidClearReferences () { if (refList != null) refList.clear (); }

}

Entry cell loses focus on button press in android but not iOS , work around?

$
0
0

I have some code in iOS where I have buttons that act like a calculator keyboard when pressed on it fills a entry field that is focused.

Works great for iOS but on android the button press even causes the entry to lose focus. I have tried to set a custom renderer for buttons and focus to false however it doesn't fix the problem.

The reason I am using this method of custom number entry is because iOS and android doesn't have a decent numeric keyboard I need on all device types and sizes.

Can anyone give me a hint of a work around?


Clear selected value from a Picker?

$
0
0

How can I clear the value from a Picker once selected (I'm assuming that this isn't possible through the standard UI as I haven't found a way to do it, so I'm trying to do it programatically).

I'm trying to add a "[clear]" item as the first item in the items collection. Then in the SelectedIndexChanged event handler, I check to see if SelectedIndex == 0. If so, I set the selected index to -1. I've verified that the index is in fact being set to -1, but the Picker continues to display the formerly selected option.

If I create a button, I can set the Picker's SelectedIndex to -1 and it works as expected (the Picker displays the Title as though a selection hasn't been made).

Appreciate any advice.

GetPositionAsync not work in Xamarin Android

$
0
0

Here is the code that I am using.
This code works on IOS but never worked on Android.
I could see some similar issues in their Project but couldn't get any help.

public async Task<Position> GetCurrentLocation()
    {
      Position position = null;
      try
      {
        var locator = CrossGeolocator.Current;
        locator.DesiredAccuracy = 100;

        position = await locator.GetLastKnownLocationAsync();

        if (position != null)
        {
          //got a cahched position, so let's use it.
          return;
        }

        if(!locator.IsGeolocationAvailable || !locator.IsGeolocationEnabled)
        {
          //not available or enabled
          return;
        }

        position = await locator.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);

      }
      catch (Exception ex)
      {
        //Display error as we have timed out or can't get location.
      }

      if(position == null)
        return;

      var output = string.Format("Time: {0} \nLat: {1} \nLong: {2} \nAltitude: {3} \nAltitude Accuracy: {4} \nAccuracy: {5} \nHeading: {6} \nSpeed: {7}",
          position.Timestamp, position.Latitude, position.Longitude,
          position.Altitude, position.AltitudeAccuracy, position.Accuracy, position.Heading, position.Speed);

      Debug.WriteLine(output);
    }

I always get task cancellation exception.

    System.Threading.Tasks.TaskCanceledException: A task was canceled.
          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00026] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__33.MoveNext () [0x0042a] in C:\projects\geolocatorplugin\src\Geolocator.Plugin.Android\GeolocatorImplementation.cs:206
        --- End of stack trace from previous location where exception was thrown ---
          at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
          at MtwPublicApp.Services.LocationService+<GetCurrentLocation>d__2.MoveNext ()

Please help me to fix
Thanks!

how to implement whatsapp like contextmenu item bar in xamarin forms

$
0
0

hi how can i display the context menu items same like whats app in xamarin forms?? can anyone guide me?

CarouselView Position problem

$
0
0

I have a CarouselView which is binded to a ObservableCollection. Whenever I add some item in that collection, I set the position of CarouselView to count - 1 of the ObservableCollection, so the view goes to recently added item. It works fine. But if I Clear that observable collection and then I add another item to that collection, the forms app crashes with index out of range. Note that I still didn't set position yet, it just crashes when i add item to the observable collection first time after clearing items. If I never set position of carousel manually, then the code works fine all the time.

is it a bug or i am doing something wrong here?

Xcode is Too New

$
0
0

Hi, I'm unable to open my storyboard. I get the following error:
Xcode is too new. This file has been edited in a version of Xcode which is unsupported by the designer. Documents saved in Xcode 9.1 format, or older, are supported.
This has just started happening? I tried re-building my solution from scratch and got the same error. I'm using Xcode verison 9.1 (9B55) . I thought to install an earlier version but can't see how that's possible. I'm using Visual Studio Community for the Mac.
I know someone has already posted something similar and said that he found a work-a-round but I could follow his solution. I've sent him a message but haven't got a response yet. Any help would be much appreciated.
Thanks,
Brian

How to add images to ACR.UserDialogs ActionSheet in UWP?

$
0
0

I am using the ACR.UserDialogs NuGet package to create cross platform ActionSheets with images. The images passed to the ActionSheetConfig object are expected to be Splat.IBitmaps which I create from local files with this line:

img = Splat.BitmapLoader.Current.LoadFromResource(resourcename, 50f, 50f).Result;

It works for iOS and Android, but hangs in UWP.

Does anyone know how to add images to a ACR.UserDialogs ActionSheet in UWP?

Could not load assembly System.Runtime in Xamarin.Forms UWP Project with .NET Standard library

$
0
0

I'm in the process of setting up a Xamarin.Forms app using .NET Standard for the shared library instead of a PCL. I've followed the instructions for doing so laid out in the blog/video on the topic (on msdn)

This is with a brand new Xamarin.Forms app, created using Visual Studio 2017 with a PCL, which was replaced with a .NET Standard library as described in the video.

The UWP app compiles fine, but throws this exception when I try to start it (on the call to Xamarin.Forms.Forms.Init)

System.IO.FileLoadException: 'Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

I've tried specifically adding the nuget package for System.Runtime, version 4.1.0 to the UWP project, but that doesn't seem to help. It runs fine in Android, but keeps giving me this exception running the UWP project. Can anyone tell me what might be causing this and how I can fix it?


CollectionView

$
0
0

Summary

A virtualized collection view that utilizes native layout controls to present an ordered set of data items using a flexible and changeable layout. The portable control must be bindable, support item templating and (optionally) support section headers.

Platform renderers would be based on the following native controls:

  • iOS: UICollectionView
  • Android: RecyclerView
  • UWP: GridView

UI virtualization is achieved in each of the native controls ensuring fast performance with large datasets.

API Changes

/// <summary>
/// A grid-like view to present an ordered set of data items using a flexible and changeable layout.
/// </summary>
public class CollectionView : View
{
    #region Bindable Properties

    /// <summary>
    /// The property bound to <see cref="Padding"/>.
    /// </summary>
    public static readonly BindableProperty PaddingProperty =
       BindableProperty.Create(
           propertyName: nameof(Padding),
           returnType: typeof(Thickness),
           declaringType: typeof(CollectionView),
           defaultValue: default(Thickness));

    /// <summary>
    /// The property bound to <see cref="RowSpacing"/>.
    /// </summary>
    public static readonly BindableProperty RowSpacingProperty =
       BindableProperty.Create(
           propertyName: nameof(RowSpacing),
           returnType: typeof(double),
           declaringType: typeof(CollectionView),
           defaultValue: default(double));

    /// <summary>
    /// The property bound to <see cref="ColumnSpacing"/>.
    /// </summary>
    public static readonly BindableProperty ColumnSpacingProperty =
       BindableProperty.Create(
           propertyName: nameof(ColumnSpacing),
           returnType: typeof(double),
           declaringType: typeof(CollectionView),
           defaultValue: default(double));

    /// <summary>
    /// Property bound to <see cref="MaxItemWidth"/>
    /// </summary>
    public static readonly BindableProperty MaxItemWidthProperty =
       BindableProperty.Create(
           propertyName: nameof(MaxItemWidth),
           returnType: typeof(double),
           declaringType: typeof(CollectionView),
           defaultValue: default(double));

    /// <summary>
    /// Property bound to <see cref="MinItemWidth"/>
    /// </summary>
    public static readonly BindableProperty MinItemWidthProperty =
       BindableProperty.Create(
           propertyName: nameof(MinItemWidth),
           returnType: typeof(double),
           declaringType: typeof(CollectionView),
           defaultValue: default(double));

    /// <summary>
    /// Property bound to <see cref="RowHeight"/>
    /// </summary>
    public static readonly BindableProperty RowHeightProperty =
       BindableProperty.Create(
           propertyName: nameof(RowHeight),
           returnType: typeof(double),
           declaringType: typeof(CollectionView),
           defaultValue: default(double));

    /// <summary>
    /// The property bound to <see cref="ItemsSource"/>.
    /// </summary>
    public static readonly BindableProperty ItemsSourceProperty =
       BindableProperty.Create(
           propertyName: nameof(ItemsSource),
           returnType: typeof(IEnumerable),
           declaringType: typeof(CollectionView),
           defaultValue: default(IEnumerable));

    /// <summary>
    /// Property bound to <see cref="ItemTemplate"/>
    /// </summary>
    public static readonly BindableProperty ItemTemplateProperty =
       BindableProperty.Create(
           propertyName: nameof(ItemTemplate),
           returnType: typeof(DataTemplate),
           declaringType: typeof(CollectionView),
           defaultValue: default(DataTemplate));

    /// <summary>
    /// Property bound to <see cref="SectionHeaderTemplate"/>
    /// </summary>
    public static readonly BindableProperty SectionHeaderTemplateProperty =
       BindableProperty.Create(
           propertyName: nameof(SectionHeaderTemplate),
           returnType: typeof(DataTemplate),
           declaringType: typeof(CollectionView),
           defaultValue: default(DataTemplate));

    /// <summary>
    /// Property bound to <see cref="SectionHeaderHeight"/>
    /// </summary>
    public static readonly BindableProperty SectionHeaderHeightProperty =
       BindableProperty.Create(
           propertyName: nameof(SectionHeaderHeight),
           returnType: typeof(double),
           declaringType: typeof(CollectionView),
           defaultValue: default(double));

    /// <summary>
    /// Property bound to <see cref="Direction"/>
    /// </summary>
    public static readonly BindableProperty DirectionProperty =
       BindableProperty.Create(
           propertyName: nameof(Direction),
           returnType: typeof(CollectionViewDirection),
           declaringType: typeof(CollectionView),
           defaultValue: CollectionViewDirection.Vertical);

    #endregion
}

Intended Use Case

The most common use would be to present items in a grid arrangement, although the control could be configurable to present items as a vertical or horizontal list. The control is intended for applications where a bindable, virtualized collection view layout is required that is not served by any of the existing Xamarin.Forms controls.

Applications:

  • Responsive, grid-based layout eg. Photo album, search results
  • Horizontal layouts
  • Custom layouts ie. Circle, flow.

android keyboard => only alpha numeric ?

$
0
0

Hello all,
i would like to know how i can set the keyboard of the edit text to accept only numeric => in the layout ?

thanks in advance for your time and your knowledge

No AOT/LLVM Option

$
0
0

Hello,

I am on a Xamarin.Forms project (using Visual Studio Community) and do not see an option to enable AOT/LLVM for the Android project. Is this option only available for Visual Studio Enterprise? I ended up enabling it manually via the csproj file and it worked. Just wondering why it doesn't have an option when using VS Community.

Kind of a side question, but as a test, I tried downloading a free trial of VS Enterprise, but it keeps saying VS Community when I open it. Can we not have two instances of VS on Mac?

Thanks!

With today update I can't deploy on the device

$
0
0

Hi guys,
I've just update Xamarin Studio for Mac and now I can't deploy apps on a device. The error is:

MismatchedApplicationIdentifierEntitlement: Upgrade's application-identifier entitlement string (F3UC5VLD5U.*) does not match installed application's application-identifier string (F3UC5VLD5U.com.portico.myInventories); rejecting upgrade.
error MT1006: Could not install the application '/Users/enricorossini/Projects/myInventories/myInventories/myInventories.iOS/bin/iPhone/Debug/device-builds/ipad6.3-10.2.1/myInventoriesOS.app' on the device 'Enrico’s iPad': AMDeviceSecureInstallApplicationBundle returned: 0xe80000be (kAMDMismatchedApplicationIdentifierEntitlementError).
--- inner exception
Xamarin.Installation.FailedInstallException: AMDeviceSecureInstallApplicationBundle returned: 0xe80000be (kAMDMismatchedApplicationIdentifierEntitlementError)
at Xamarin.Installation.InstallationProxyService.InstallApplicationBundle (System.String app_path, MonoTouch.MobileDevice.ProgressCallback callback, System.String shadow_directory) [0x000f5] in :0
at Xamarin.Launcher.DevController.InstallApplicationBundle (Xamarin.Hosting.RealDevice d, Xamarin.Hosting.AppBundle bundle, System.String shadow_directory) [0x0003d] in :0
at Xamarin.Launcher.DevController+c__async0+c__AnonStorey9.<>m__0 () [0x00000] in :0
at Xamarin.Hosting.RealDevice.ExecuteWithSession (System.Action action) [0x0000e] in <26d23b8a977048db99c7be2b68926132>:0
at Xamarin.Launcher.DevController+c__async0.MoveNext () [0x000c2] in :0
--- End of stack trace from previous location where exception was thrown ---
at Xamarin.Utils.NSRunLoopExtensions.RunUntilTaskCompletion (Foundation.NSRunLoop this, System.Threading.Tasks.Task task) [0x00070] in <26d23b8a977048db99c7be2b68926132>:0

at Xamarin.Launcher.DevController.InstallApplication (System.String device_name, System.String device_type, System.String app_path) [0x00166] in :0

at Xamarin.Launcher.DevController.InstallApplication (System.String device_name, System.String device_type, System.String app_path) [0x001cb] in :0
at Xamarin.Launcher.Driver.Main2 (System.String[] args) [0x009db] in :0
at Xamarin.Launcher.Driver.Main (System.String[] args) [0x00074] in :0

Application could not be uploaded to the device.

What does it mean? What can I do to fix it? Thanks

Is there a way to get XAML binding intellisense in a separate ContentView file used in a ListView?

$
0
0

I have a ListView with this item template:

<ListView.ItemTemplate>
  <DataTemplate>
    <ViewCell>
      <views:ProjectListEntry />
    </ViewCell>
  </DataTemplate>
</ListView.ItemTemplate>

ProjectListEntry is fairly complex and is used in another ListView, so I have it in its own file. I've set it up like this:

<ContentView
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    ...
    BindingContext="{x:Static helpers:DesignTimeData.ProjectListEntryVm}">

As you can see, to get Intellisense, I tried to set BindingContext to a static member on the DesignTimeData class. This works fine for my Pages (where I replace the BindingContext at runtime), but for ContentViews used in ListViews, the ContentView's BindingContext seems to be inherited (from the ViewCell, I guess). This means that the explicit BindingContext on my ContentView will actually override the BindingContext set on the ViewCell by the ListView, and all my list elements will reflect the static design-time data at runtime. But if I remove the BindingContext, I get no intellisense for the members I bind to inside the ContentView file.

Is there a simple way to get Intellisense for bindings in a ContentView like this? (As mentioned, I can't inline the ContentView in the ListView definition, because the ContentView is fairly complex and used in several lists. I also can't use some kind of VM locator, because although I'm using bindings, I'm not using "full" MVVM - I'm using a Redux-like architecture instead. And I guess a VM locator wouldn't work for this case anyway for the same reasons the above doesn't work.)

Viewing all 204402 articles
Browse latest View live


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