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

How to catch a timeout exception

$
0
0

I am working on a Xamarin Forms application that supports both android and iOS. In my application HTTPClient have a time out of 30 seconds and when there is no response with in mentioned time out, it is throwing a exception. tried to catch the exception using TaskCanceledException and TimeoutException but it was triggering none of these these exception. Please some help me by sharing more information on how we will be able to identify the time out exception in our xamarin forms application.

The exception that was caught was something line Java.IO.IOException when testing my app in android version. Any info will be helpful. Is there any one who have ran into the same issue.


Xamarin UI Tests: AutomationId not getting translated to a Label

$
0
0

Currently using VS2019 with Xamarin.Forms version 4.2.0.848062 and doing a targeted build for Android 9.0. App works great, but testing has been a pain.
Issue right now is that I have some XAML looking like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage 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"
             x:Class="MyApp.Views.AddThingView"
             Title="Add New Thing">

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Add" Clicked="Add_Thing" />
    </ContentPage.ToolbarItems>

    <ContentPage.Content>
        <StackLayout>

            <Label AutomationId="ThingName" Text="Thing Name" FontSize="24" VerticalOptions="Center"/>
            <Entry Text="{Binding ThingName}" AutomationId="ThingNameEntry" Placeholder="Enter Name Here" VerticalOptions="Center" />

            <Label AutomationId="ThingDescription" Text="Description" FontSize="24" VerticalOptions="Center" />
            <Entry Text="{Binding Description}" AutomationId="ThingDescriptionEntry" Placeholder="Enter Description Here" VerticalOptions="Center" />

        </StackLayout>
    </ContentPage.Content>
</ContentPage>

My test then looks like this:

public void TestAddThing()
        {
            AppResult[] results = app.WaitForElement(c => c.Marked("Things"));
            app.Screenshot("Welcome screen.");

            Assert.AreEqual(results.Length, 1);

            app.Tap(x => x.Class("ActionMenuItemView").Index(0)); //This navigates to the page for adding "things"
            app.Repl();  //i when I do a "tree" in the repl() loop
            app.EnterText("ThingNameEntry", "Thing 1");
            app.EnterText(c => c.Marked("ThingDescriptionEntry"), "This is our first thing.");

        }

The issue right now is that the app.EnterText(...) methods are not working (they time out and the runner complains it can't find an element marked as "ThingNameEntry" or "ThingDescriptionEntry".
When I do a 'tree' in the repl that the app spins up, I see the following:

[[object CalabashRootView] > DecorView]
  [LinearLayout > FrameLayout]
    [FitWindowsFrameLayout] id: "action_bar_root"
      [ContentFrameLayout > ... > PlatformRenderer] id: "content"
        [NavigationPageRenderer] id: "NoResourceEntry-1"
          [PageContainer] id: "NoResourceEntry-10"
            [PageRenderer > Platform_DefaultRenderer] id: "NoResourceEntry-5"
              [LabelRenderer] id: "NoResourceEntry-6" text: "Thing Name"
              [EntryRenderer]
                [FormsEditText] id: "NoResourceEntry-7"
              [LabelRenderer] id: "NoResourceEntry-8" text: "Description"
              [EntryRenderer]
                [FormsEditText] id: "NoResourceEntry-9"
          [Toolbar] id: "toolbar"
            [ActionMenuView]
              [ActionMenuItemView] id: "NoResourceEntry-0" text: "Add"
            [AppCompatTextView] text: "Add New Thing"
            [AppCompatImageButton]
  [View] id: "navigationBarBackground"
  [View] id: "statusBarBackground"

Does ANYONE know why the automationId's are not getting translated into labels?

I will say this is an extremely frustrating acceptance test framework to use. As you can see I wasn't able to pull automationId's off the toolbar item either and had to revert to a relatively ungraceful "x.class(....)" workaround. Hopefully there is a similarly easy workaround for this.

Suggestions?

Reference Forms Embedded Font in Android app project

$
0
0

Hello!

I am setting up a custom shell renderer in my Android project so that I can swap out the font of my bottom tabs. I have added the font to my shared project as described here. I am able to reference the font in my iOS project like so:

tab.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName("NAMEOFFONT", 12) }, UIControlState.Normal);

and this works beautifully with no extra steps.

I cannot find how to do the same in Android though, as the method is expecting an int value (i.e. an Android Resource):

bottomView.ItemTextAppearanceActive = Resource.Style.BottomTabBarFontStyle;
bottomView.ItemTextAppearanceInactive = Resource.Style.BottomTabBarFontStyle;

The only way I have found to be able to do this is by adding (duplicating) the font to my Android project as an Android Resource and creating a Style for it, as you would do in a classic Android project.

I guess my question is then is there a way of referencing that Embedded Font from my Android project to save adding it in a second time?

Many thanks!

Will

Setting a native UIBarButtonItem in Xamarin Forms

$
0
0

I am using Xamarin Forms and would like to set a native UIBarButtonItem in the iOS navigation bar.

I've created a custom PageRenderer and overridden the ViewDidLoad() method to add a Done button on the right of the navigationItem. The code is being executed but the UIBarButtonItem doesn't appear. I've also tried executing this in ViewWillAppear and ViewDidAppear but no Done button appears.

Can anyone help me with why this doesn't work?

[assembly: ExportRendererAttribute(typeof(OTContentPage), typeof(OTContentPageRenderer))]

namespace OurGalaxyX.iOS
{
    public class OTContentPageRenderer : PageRenderer
    {
        public OTContentPageRenderer() : base()
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (this.NavigationController != null)
            {
                var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, args) =>
                {
                    this.NavigationController.PopViewController(true);
                });
                doneButton.TintColor = UIColor.Yellow;
                this.NavigationController.TopViewController.NavigationItem.RightBarButtonItem = doneButton;
            }
        }
}
}

Is it possible to integrate the HERE Maps Android/iOS SDKs into a xam.forms project?

$
0
0

Hi =)

So I believe there are two previous discussions on this:

https://forums.xamarin.com/discussion/43630/xamarin-binding-for-here-maps-problem
https://forums.xamarin.com/discussion/102803/binding-libary-incompatibility-here-maps-sdk

Currently I'm using: SDK Version: 3.11.2.82 (Premium)

The Android SDK comes as an .AAR, after extracting the .JAR, creating a Android binding library, and removing classes throwing errors:

<metadata>
  <remove-node path="/api/package[@name='com.here.android.mpa.pde']/class[@name='PlatformDataItem']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.pde']/class[@name='PlatformDataItemCollection']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.pde']/class[@name='PlatformDataResult']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='DiscoveryRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='TextSuggestionRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='TextAutoSuggestionRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='GeocodeRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='GeocodeRequest2']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='ImageMedia']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='PlaceRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.mapping']/class[@name='MapOffScreenRenderer']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.streetlevel']/class[@name='StreetLevelModel']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.streetlevel']/class[@name='StreetLevelOffScreenCapture']" />
  <remove-node path="/api/package[@name='com.here.odnp.util']/class[@name='OdnpIOUtils']" />
  <remove-node path="/api/package[@name='com.here.odnp.util']/class[@name='AlarmTimer']" />
  <remove-node path="/api/package[@name='com.here.odnp.util']/class[@name='AssetCopyTask']" />
  <remove-node path="/api/package[@name='com.here.odnp.wifi']/class[@name='WifiFilterRx']" />
  <remove-node path="/api/package[@name='com.here.odnp.wifi']/class[@name='WifiFilterTimestamp']" />
  <remove-node path="/api/package[@name='com.here.odnp.posclient.pos']/class[@name='PositioningSession']" />
  <remove-node path="/api/package[@name='com.here.services.playback.internal.util']/class[@name='PlaybackReader']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal.util']/class[@name='IRadioMapManager']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal.util']/class[@name='RadioMapManager']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal']/class[@name='IRadioMapManager']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal']/class[@name='RadioMapManager']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='StringNativeMap']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='StringNativeVector']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='NavigationManagerImpl']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='StringNativeVector']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='MapImpl']" />
  <remove-node path="/api/package[@name='com.here.sdk.analytics']/class[@name='HEREAnalytics']" />
</metadata>

I got my dll, but have a very good feeling it won't work =)

The iOS SDK comes as a NMAKit.framework, is there even a remote chance of finding a way to reference this in Xamarin?

Has anyone had any recent success with implementing HERE Maps in Xamarin?

ListView ItemTapped/ItemSelected triggered on iOS when panning in the SidePanel of MasterDetailPage

$
0
0

Hi,

we upgraded Xamarin Forms iOS from 4.2 to 4.7 and observed the following behaviour change in MasterDetailPage:

We have a MasterDetailPage. Master is a side panel with menu items and in Detail there is a NavigationPage with a list view.

In Forms 4.2, when the list view in Detail is visible, we could drag with the finger on the screen from left to right to drag the side panel into the screen. When we lift the finger up from the screen, the side panel will be presented fully. We can drag the side panel back again without triggering the itemTapped/itemSelected of the listview in the Detail Screen.

In Forms 4.7, when we drag with the finger on the list view from left to right and then lift the finger up from the screen, the itemTapped/itemSelected is triggered of the listview for the item where the finger was touched. That's bad. Everytime when I drag in the side panel, I activate an list item and you see the animation to the next page on right area of the screen.

This behaviour is not desired and I think this is a bug, or? Is there a workaround for it, with CustomRenderers?

On Android, this is not a problem. The side panel can be dragged in by dragging from the left edge to the right without triggering the itemselected of the list view. This works in Forms 4.2 and 4.7.

Best regards,
Mario

share a image with text on whatsapp

$
0
0

Hi

I want a share a image on whatsapp with text. how it possible with Xamarin.Essentials. currently share only image work fine but with text how it is possible. kindly guide me any solution.

Thanks

Status bar not hiding on iOS

$
0
0

I see there have been a number of questions on how to hide the status bar on iOS when using Xamarin Forms. I believe I have tried everything suggested but the status bar at the top of the screen persists in showing. I've done:

Added this to the Info.plist:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

Added this to the iOS AppDelegate.cs (in the FinishedLaunching() method after LoadApplication()):

        UIApplication.SharedApplication.SetStatusBarHidden(true, false);
        UIApplication.SharedApplication.StatusBarHidden = true;

And I've added this to my main page's xaml

xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.PrefersStatusBarHidden="True"

None of these seem to be working. I believe I'm using the latest Xamarin packages. Testing on iOS 13.5.1

Thanks for any help.

Bill


Timepicker Error inflating class

$
0
0

I have a Timepicker as below:

<StackLayout x:Name="stl1"
     VerticalOptions="FillAndExpand"
         HorizontalOptions="FillAndExpand"
     Orientation="Vertical"
         >

         <Label Text="Date" />
         <DatePicker x:Name="dat1" HorizontalOptions="FillAndExpand" />

         <Label Text="Time" />
         <TimePicker x:Name="tim1" HorizontalOptions="FillAndExpand" />
</StackLayout>

As soon as I click it on-screen I get this error:

Android.Views.InflateException: 'Binary XML file line #20: Error inflating class android.widget.TimePicker'

There is no code-behind related to the TimePicker and the DatePicker works just fine. I have tried cleaning and rebuilding the solution but that did nothing.

I have seen some mention of a similar error when the time picker is in a scroll view but I have it in a simple StackLayout as above.

This is on version 4.4.0.991640.

Unable to Detect SmartPhones Using Plugin.BLE

$
0
0

Hello Everyone,
Currently i'm facing problem in finding smartphones(OnePlus and OPPO) using plugin.ble. Is there any alternate nuget for finding smartphone in xamarin forms? If so, Kindly let me know!

Thanks in Advance!!

Tapping ListView Items to navigate to other views

$
0
0

I have a Listview, and want to navigate to other views based on the listview items I tap, each item navigating to a different view. I know I could probably do this without a listview, using a stacklayout of some sort, but is it possible to accomplish this through a listview?
Note: I want this to be my "home page" of a quiz app, and that tapping an item in the listview will take me to that specific quiz.( I think that by having this in a listview it'll look organized and uniform.)

Also, can somebody please tell me how to better format these questions?? I want my question to be with a white background while my code has a grayish one, but for some reason it's showing up like this (code and comments all mixed up?)

Home.xaml


<Grid.RowDefinitions>

</Grid.RowDefinitions>

        <ListView  x:Name="MainListView" 
         HasUnevenRows="True"
                  >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="30">
                            <Label HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" TextColor="Black" FontSize="30" Text="{Binding Section}"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>

Home.xaml.cs

public partial class Home : ContentPage
{

    public IList<Categorias> Categories { get; private set; }

public Home()
{

InitializeComponent();

MainListView.ItemsSource = Categories;

       Categories = new List<Categorias>();

      Categories(new Categorias
        {
            Section = "Section1",

        });

        Categories(new Categorias
        {
            Section = "Section2",

        });

      ...

Developing a Location Background Service

$
0
0

Hi

I want my app to send a location every x minuttes, both when using the app, but also when the app is in the background.

I seen a few example of how to create a service which is running in the background with xamarin.android. (https://github.com/xamarin/mobile-samples/tree/master/BackgroundLocationDemo)

But what about xamarin.forms, which I'm working on? Could the same code be used with forms? Also I haven't seen the same for xamarin.ios.

Why can't I find a full example code of sending locations from a app, both foreground and background? I'm convinced a lot of developers could be interested in such functionallity.

I'm very new to xamarin, so I'm hoping you can point me in the right direction if its possible to develop such funcionallity.

Kind regards

How to fix cinema hd not streams?

$
0
0

Hi everybody,
My cinema hd app suddenly didn't work, it announced non-streaming programs and movies. I have checked the connection as well as restarting the device but the situation has not improved.
Right now I am unable to do anything with free cinema, whether it is having difficulties. Someone had a problem please help me solve it.
Thanks for reading.

Xamarin forms i a getting this error after updating visual studio

$
0
0

Java.Lang.NoSuchMethodError: 'no non-static method "Landroidx/fragment/app/FragmentTransaction;.add(ILandroidx/fragment/app/Fragment;)Landroidx/fragment/app/FragmentTransaction;"'

Older versions of android don't load an app

$
0
0

Good day,

i was hoping someone could help me, i'm pretty new to Xamarin.
my app works perfectly on newer devices android 9 and 10 but older devices it doesn't seem to work at all.

LG stylus 3 - android 7.0: The app loads and works okayish the first time, after the first load none of the images display (This includes ImageButtons)
Sony Xperia - android 5.0: The app wont load at all just crashes, crashes instantly within 3 seconds.

I have tried to load demo apps to both devices with the same result.


Admob - Test banner ad appear, but real banner ad doesn't appear on XamarinForms app

$
0
0

I developed my first app using the XamrinForms, I'm new to Admob, I used Test banner Ad and it worked well, but when using the real banner on a real device the ad doesn't appear, I searched about this problem and i found some devlopers say that "The ad on the real device It may doesn't appear because it may take some time and many requests for AD to build AD resources". As for the time, I have waited for more than three days. As for the number of requests, I didn't understand them well. For example, how many requests does the ad require to appear? Does this mean that ads will not appear until after uploading the app to Google Play and downloading it by many users?

By the way, the real ad appears on the emulator as a test ad, but on the real device it doesn't appear at all

Sorry about my bad english

Simple binding not working - what did I not understand?

$
0
0

Hello

Learning about Xamarin.Forms is exciting - but for the past many hours I have been working a problem:
It seems that I forgot some very basic knowledge of how to bind a variable to a XAML item (like a label). Could someone please tell me what I am missing to make this simple binding work? I believe I had something like this working days ago, but seem to have lost the working example.

Please tell me what I am missing in this simple "Hello World!" example. As seen in the attached picture, I am missing "World!".

file: BindingTest.cs
`
using System;
using Xamarin.Forms;

namespace BindingTest
{
public class App : Application
{
public App ()
{
// The root page of your application
MainPage = new MyPage(); // Show my simple page when APP is starting
}

    protected override void OnStart ()
    {
        // Handle when your app starts
    }

    protected override void OnSleep ()
    {
        // Handle when your app sleeps
    }

    protected override void OnResume ()
    {
        // Handle when your app resumes
    }
}

}
`

File: MyPage.xaml
<?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="BindingTest.MyPage"> <ContentPage.Content> <StackLayout HorizontalOptions="Center" VerticalOptions="Center"> <Label Text="Hello"/> <!-- This label should be visible just below 'Hello' - binding the 'randomText' to the variable in MyPage.xaml.cs --> <Label Text="{Binding randomText}"/> </StackLayout> </ContentPage.Content> </ContentPage>

File: MyPage.xaml.cs
`
using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace BindingTest
{
public partial class MyPage : ContentPage
{
public string randomText { get; set; }

    public MyPage ()
    {
        randomText = "World!";
        InitializeComponent ();
    }
}

}
`

How to change the background color of the label on the label selection

$
0
0

when the user select the tab from vertical tabs then the background color and shape should be same as in screen short how to achieve

Set RowSpan with Converter

$
0
0

Hello guys,

I would like to have uneven rows in my ListView... what I do is to set the

HasUnevenRows="true"

and

<Label Grid.Row="0" Grid.RowSpan="{Binding Description, Converter={StaticResource ConverterHasValueToRowSpan}}" Text="asd"/>

and follows the converter:

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
        if (value == null)
        {
            return int.Parse("0");
        }

        return string.IsNullOrEmpty(value.ToString()) ? int.Parse("2") : int.Parse("0");
        }

I also tried without the integer parsing and I still get the error message:

Value was an invalid value for RowSpan. Parameter name: value

Can anyone help? It seems to me that I didn't forgot something.

System.TypeInitializationException has been thrown!

$
0
0

I create custom control for my project, in which I customize the cell of DataTemplete in CollectionView.ItemTemple, but when page is run the Type Initialization Exception is occurs! is there any solution?

Viewing all 79144 articles
Browse latest View live


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