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

Two way binding with a converter causing an infinite loop

$
0
0

I have a field
public string Test
{
get
{
return _test;
}
set
{
if (value != _test)
{
_test = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Test"));
}
}
}
which is bound in xaml

This works fine without the converter however as soon as I add the converter back in regardless of the code in the converter (which is why i havnt bothered posting the code for it, I have even tried it with convert and convert back both returning empty strings) No matter what happens as soon as I enter something into the field it starts an infinite loop of hitting ConvertBack. Each time it adds whatever i entered again. E.g. if I enter 1 into the entry it hits ConvertBack with value 1 and works fine. It then hits ConvertBack again with 11, it then hits it again with 111

Even if I close the app it carries on entering ones into a search window until I press some other button and can not figure out why


Xamarin Multple Errors | Can't Archive HelloWorld APK

$
0
0

First of all it takes 5 mints to archive,

And whenever I Build or archive, Xamarin won't able to do it,

I tried reinstall windows + xamarin + Visual studio

Also tried to find answer on different forums,
Didnt get anything,
Even I don't change any code in helloworld apk.

My information:

Mode = Release
Target Framework = Android 9.0 PIE

Error1:The executable is not a valid application.

Occurs = Win_10/7_x86_bit + Visual_Studio 2019:

Unhandled exception: System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Xamarin.Android.Tasks.CompileNativeAssembly.RunAssembler(Config config)
   at Xamarin.Android.Tasks.AsyncTaskExtensions.<>c__DisplayClass0_1`1.<WhenAll>b__0()  App8.Android            
Error       Unhandled exception: System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Xamarin.Android.Tasks.CompileNativeAssembly.RunAssembler(Config config)
   at Xamarin.Android.Tasks.AsyncTaskExtensions.<>c__DisplayClass0_1`1.<WhenAll>b__0()  App8.Android            

1>------ Build started: Project: App8, Configuration: Release Any CPU ------
1>App8 -> C:\Users\Administrator\source\repos\App8\App8\App8\bin\Release\netstandard2.0\App8.dll
2>------ Build started: Project: App8.Android, Configuration: Release Any CPU ------
2>  App8.Android -> C:\Users\Administrator\source\repos\App8\App8\App8.Android\bin\Release\App8.Android.dll
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000: Unhandled exception: System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at System.Diagnostics.Process.Start()
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at Xamarin.Android.Tasks.CompileNativeAssembly.RunAssembler(Config config)
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at Xamarin.Android.Tasks.AsyncTaskExtensions.<>c__DisplayClass0_1`1.<WhenAll>b__0()
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000: Unhandled exception: System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at System.Diagnostics.Process.Start()
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at Xamarin.Android.Tasks.CompileNativeAssembly.RunAssembler(Config config)
2>C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2447,3): error XA0000:    at Xamarin.Android.Tasks.AsyncTaskExtensions.<>c__DisplayClass0_1`1.<WhenAll>b__0()
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Error2:The executable is not a valid application.

Occurs = Win_7_x86_bit + Visual_Studio 2017:

It was building archive before but not works now.

"java.exe" exited with code 1.  App10.Android           
1>------ Build started: Project: App10, Configuration: Debug Any CPU ------
1>App10 -> C:\Users\Administrator\source\repos\App10\App10\App10\bin\Debug\netstandard2.0\App10.dll
2>------ Build started: Project: App10.Android, Configuration: Debug Any CPU ------
2>  App10.Android -> C:\Users\Administrator\source\repos\App10\App10\App10.Android\bin\Debug\App10.Android.dll
2>  No way to resolve conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e". Choosing "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" arbitrarily.
2>C:\Program Files\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2610,3): error MSB6006: "java.exe" exited with code 1.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I will never use Xamrin again in my life,
But due to my project is based on it(libvlcsharp),
Feel free to ask any info If I didn't added it. Thanks.

AudioManager Issue...

$
0
0

I need turn on the speaker when the call state is equal to offhook...
I add permission into the manifiest like this:
And... i'm using this code to try turn on the speaker...

AudioManager audioManager = (AudioManager)Android.App.Application.Context.GetSystemService(Context.AudioService);
audioManager.Mode = Mode.InCall;
audioManager.SpeakerphoneOn = true;

The proccess makes a call saccessfully... but the speaker doen't work. It is turn off...

What's the issue here? Thanks!

App crashes after inserting to SQLite database - "method arguments are incompatible"?

$
0
0

Hi everyone,
My app calls data from a web API in XML form, deserializes it with Newtonsoft.JsonConvert, and now I'm trying to get it to insert that data into a local SQLite database within the app. Here's my code:

`public MainPage()
{
InitializeComponent();
}

    public async void GetLocations()
    {
        var httpClient = new HttpClient();
        var response = await httpClient.GetStringAsync("my API url is here");
        var locations = JsonConvert.DeserializeObject<List<Location>>(response);
        SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
        conn.CreateTable<Location>();
        conn.Insert(locations);
        conn.Close();


    }

private void Button_Clicked(object sender, EventArgs e)
{
GetLocations();

        //await Navigation.PushAsync(new LocationPage());
    }
}`

So I've put breakpoints on the last three lines within the GetLocations method, and the first two go off perfectly; QuickWatch tells me all the data has been inserted successfully into the correct format. It's after that, presumably when I try to close the table connection (there are multiple tables of data I have to insert so I need to close each one at the end of each method) that the app crashes and I get "System.ArgumentException: 'method arguments are incompatible'". It does not hit the conn.Close(); breakpoint at all, it finishes the insert and then throws the exception. I'm thinking it may have to do with the method types, I'm not 100% sure on how to use async and void methods together properly.

Any help is greatly appreciated, thanks very much.

Loader not running when calling tcp request.

$
0
0

I am using userdialog for loader. loader work perfectly when we not send any request and if we send any tcp request then it stop working may be it is a thread problem.

Video Compression in Xamarin.Forms

$
0
0

Hi,
I am using Xam.Plugin.Media to get video from camera/gallery now i need to get the size of that video also i need to compress the size. Please suggest how to get Media File size and how to compress media in Xamarin.Forms

Thanks in Advance.

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.

UseSafeArea not working correctly

$
0
0

I have a CollectionView, which contains a CollectionView, which contains a FlexLayout.
The top CollectionView is being used as a Carousel to contain the other CollectionViews.

When I use ios:Page.UseSafeArea="true", it does not handle adding the additional safe area correctly.

If I turn the iPhone to landscape mode, with the notch on the right, then the right edge of the FlexLayout is cut off by the safe area. The left edge starts at the safe area as it should.

It's as if the FlexLayout does not realize that the area it is to be drawn into, has been made shorter by UseSafeArea.

So what is going on and how do I fix it?


Drag and Drop on Xamarin Forms

$
0
0

Hi,
We want to implement drag and drop functionality in Xamarin forms

and in this user should be able to drag an emoji from 1 place, and put on another. We don’t want the source emoji to go away though and should be able to come to know on which employee, rating is given .


We have checked a few links like below, but none of them seem to work:

https://stackoverflow.com/questions/49515451/xamarin-forms-drag-image-between-views
https://blog.francois.raminosona.com/drag-and-drop-in-xamarin-forms/

Will appreciate if could get some tips on how to do it and even if this was possible on forms?

Picker binding the selected item in pageload

$
0
0

Hi All,

Need your help pls as cant figure out why my picker is populated with all available data through REST API but as once I am retrieving the whole product data on pageload the related category is not being selected automatically. Thanks.

My VM:

    private ObservableCollection<Category> _AllCats;
    public ObservableCollection<Category> AllCats
    {
        set
        {
            this._AllCats = value;
            OnPropertyChanged();
        }
        get
        {
            return this._AllCats;
        }
    }


    private Category _SelectedCat;
    public Category SelectedCat
    {           
       set
        {
            this._SelectedCat = value;
            OnPropertyChanged();
        }
        get
        {
            return this._SelectedCat;
        }
    }


  public ProdsMngtDetailViewModel(Product product , Category selectedcat)
    {
        GetCatsAsync();
        SelectedCat = selectedcat;
        SelectedProduct = product;
        CategoriesService cs = new CategoriesService();
        AllCats = cs.GetAllCats2();
    }

Random WebService Timeouts

$
0
0

I am getting random webservice timeouts and I can't figure out why, it is only happening when calling the webservice from the Xamarin app. If I test the webservice in SoapUI, and even spam it with requests, I get 100% success and return values. But when calling the same webservice in Xamarin about 30% of the calls never return and eventually timeout. But on the backend I and see the calls 100% of the calls made it to the webservice and worked, but Xamarin isn't getting the response 30% of the time.

Webservice is C# asmx webservice, which is added via the connected services in the Xamarin project.

The call is pretty simple

PhoneWSServiceReference.PhoneWebServiceSoapClient wsclient = new PhoneWebServiceSoapClient(EndPointName); WSHelper.SetWSTimeOut(ref wsclient, 20); BaseResponse response = wsclient.UserLogin(UserName, Password);

But 30% of the time I get "System.TimeoutException: 'The operation has timed out.'"

I am using the IsBusy flag, setting it to true just before the webservice call and false after it. Is there a better way to call the asmx webservices?

I expect to get an infinite loop when I implement IValueConverter but there isn't.

$
0
0

I have an Entry text which is binded in TwoWay mode to a simple string.
In Convert() I add the letter "S" ("for came from Source")
In ConvertBack() I add the letter "T" ("for came from Target").

Now, when I write something in the entry (lets say I write the string "A"), I expect the next phases to occur:
1. The Target was changed, so ConvertBack() should be called, and send the string AT to the source (Because the converter adds "T").
2. Therefore the Source was changed, so Convert() should be called and send the string ATS to the Target (Because the converter adds "S")..
3. Therefore the Target was changed, so ConvertBack() should be called, and send the string ATST to the source.
4. Therefore the Source was changed, so Convert() should be called and send the string ATSTS to the Target.
5. and on and on and on......Endlessly.

Of some reason It doesn't happen ( ConvertBack() is being called, then Convert() is being called and that's it).

Why isn't an infinite loop over here?

This is the converter:

public class NiceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string resultAfterConvert = value as string + "S";
            return resultAfterConvert;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string resultAfterConvert = value as string + "T";
            return resultAfterConvert;
        }
    }

Is it possible to set focus to a Grid element?

$
0
0

Hi,

We have a scrollable Grid element with label elements loaded in each row. My requirement is to navigate selection of grid items using keyboard buttons in UWP platform. I couldn't possibly find any solution to set the focus for either the Grid or its child Label element. Is it possible to set focus for Grid element or switch focus across the label elements? Or the editable elements such as Editor, Entry, SearchBar will only receive focus? If So why would the Button element receive focus?

Can someone explain this behavior.

Thanks & Regards,
Muthu

How to Attach Debugger to a Running Android or IOS app?

$
0
0

I often start an app just to see how it works, then I decide to debug, so I just attach to its process and debugging kicks in.

But I am not able to find how to attach to a running Xamarin Forms app process to start debugging.

To clarify, I know how to debug and that works fine but how do I attach debugger to a running Xamarin Forms app to debug?

Why the player Id is empty from oneSignal on Xamarin? Just in iOS

$
0
0

I'm having a little problem getting the player Id from Xamarin. I'm making an application in Xamarin Forms, it works for Android, but when I try to get it on iOS the string is Empty.

Then, when I want to get the value of "playerId" (My var) it is Empty. This happens just in iOS--when I do this on Android it works fine. Obviously before I register the app with the OneSignal Key, my device(iPhone) is registered on the OneSignal page and I can receive push notifications. I need get the playerId to save it on my DataBase.

This is my code:

string playerId="";

OneSignal.Current.IdsAvailable(new Com.OneSignal.Abstractions.IdsAvailableCallback((playerID, pushToken) =>
                            {
                                playerId = playerID;
                            }));

Camera2 Sample

$
0
0

Is there any sample of a simple Camera2 API implementation on Android in Xamarin Forms?

Media Element crash when navigating away from page on Ios

$
0
0

I am getting Media Element disposing exception when I navigate back to a previous page from a page where I have my Media Element.

The managed Managed Stacktrace:

          at <unknown> <0xffffffff>
          at ObjCRuntime.Messaging:void_objc_msgSend_IntPtr <0x00007>
          at AVFoundation.AVPlayer:ReplaceCurrentItemWithPlayerItem <0x0005b>
          at Xamarin.Forms.Platform.iOS.MediaElementRenderer:Dispose <0x002b7>
          at Foundation.NSObject:Dispose <0x00023>

My steps to reproduce were:
Push new page with MediaElement. Click play on video.
Click back to pop page.
Page does pop but UI becomes unresponsive.

my code is:

public partial class SermonsMediaPlayer : ContentPage
            {
                private Sermon Sermon;

                public SermonsMediaPlayer(Sermon selectedSermon)
                {
                    InitializeComponent();

                    if (selectedSermon is null)
                    {
                        Sermon = new Sermon();
                    }

                    Sermon = selectedSermon;
                    BindingContext = Sermon;

                }

                async void Back_Clicked(object sender, EventArgs args)
                {
                    // release media resources
                    if (mediaPlayer.CurrentState == MediaElementState.Playing)
                    {

                        mediaPlayer.Stop();
                        await Navigation.PopModalAsync();
                    }

                    await Navigation.PopModalAsync();
                }

                protected override void OnDisappearing()
                {
                    base.OnDisappearing();
                }
            }


        <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xxxViews.SermonsMediaPlayer">
            <ContentPage.ToolbarItems>
                <ToolbarItem Text="Back" Clicked="Back_Clicked" />
            </ContentPage.ToolbarItems>
            <ContentPage.Content>
                <Grid>
                    <MediaElement x:Name="mediaPlayer" Source="{Binding Url}" AutoPlay="False"
                      ShowsPlaybackControls="True" KeepScreenOn="False" />
                </Grid>
            </ContentPage.Content>
        </ContentPage>

How to deserialize JSON

$
0
0

I am developing an application with xamarin forms.I have a json data I pulled from the url, I do this operation via method.

var url = await _ContractService.GetContractList();

var json = url.Content.Items;

I want to deserialize this data I have taken. because i'm printing some data i get from json on listview

I want to redirect other information about the same data to another page with listview item selected.

Please help me I couldn't at least an idea

public class ContractList
 {
     public List<Item> Items { get; set; }
     public long PageIndex { get; set; }
     public long PageCount { get; set; }
     public long RecordCount { get; set; }
 }

 public class Contract
 {
     public long Id { get; set; }
     public string CompanyCode { get; set; }
     public string OCompanyCode { get; set; }
     public long? OutletNumber { get; set; }
     public string OutletName { get; set; }
     public long? MasterOutletNumber { get; set; }
     public string MasterOutletName { get; set; }
     public string CustomerCode { get; set; }
     public long ContractUniqueNumber { get; set; }
     public object MyaContractNumber { get; set; }
     public long? OutletTradeGroupCode { get; set; }
     public string OutletTradeGroupText { get; set; }
     public long? KeyAccountCode { get; set; }
     public string KeyAccountText { get; set; }
     public long ContractNumber { get; set; }
     public string Definition { get; set; }
     public long EpNumber { get; set; }
     public long VersionNumber { get; set; }
     public DateTimeOffset StartDate { get; set; }
     public DateTimeOffset? EpStartDate { get; set; }
     public object MyaepStartDate { get; set; }
     public DateTimeOffset EndDate { get; set; }
     public DateTimeOffset? ValidEndDate { get; set; }
     public DateTimeOffset CreateDate { get; set; }
     public long ContractState { get; set; }
     public long WorkFlowApprovalStatusCode { get; set; }
     public string CustomerName { get; set; }
     public CustomerType CustomerType { get; set; }
     public OutletBusinessTypeExtensionCode? OutletBusinessTypeExtensionCode { get; set; }
     public OutletSegmentCode? OutletSegmentCode { get; set; }
     public long? OutletSalesCenterCode { get; set; }
     public long ContractScopeCode { get; set; }
     public string ContractScopeName { get; set; }
     public long Quota { get; set; }
     public QuotaName QuotaName { get; set; }
     public long? QuotaAmount { get; set; }
     public long? OutletSubTradeChannelCode { get; set; }
     public long PromotionTypeCode { get; set; }
     public object PromotionTypeName { get; set; }
     public WorkFlowApprovalStatusName WorkFlowApprovalStatusName { get; set; }
     public long ContractType { get; set; }
     public bool IsTemplate { get; set; }
     public long? PaymentTypeCode { get; set; }
     public PaymentTypeName? PaymentTypeName { get; set; }
     public DistBusinessTypeExtensionCode? DistBusinessTypeExtensionCode { get; set; }
     public DistBusinessTypeExtensionCode? ODistBusinessTypeExtensionCode { get; set; }
     public long? DistNumber { get; set; }
     public OutletChannelCode? OutletChannelCode { get; set; }
     public object SwitchOutletNumber { get; set; }
     public long CaseTypeCode { get; set; }
     public object SwitchDate { get; set; }
     public long CreateUser { get; set; }
     public object CreateUserTitle { get; set; }
     public long? OldContractUniqueNumber { get; set; }
     public bool HasEp { get; set; }
     public bool HasRevized { get; set; }
     public bool IsFixedPriced { get; set; }
     public bool IsCustomerContract { get; set; }
     public object DistChangeText { get; set; }
     public long AttachmentCount { get; set; }
     public double? CompletionRatio { get; set; }
     public CountryCode CountryCode { get; set; }
     public bool Promotion { get; set; }
     public bool? FreeTimeBased { get; set; }
     public string OutletLocationCode { get; set; }
     public DistBusinessTypeExtensionCode? PlDistType { get; set; }
     public long? Defertment { get; set; }
     public bool HasWarranty { get; set; }
     public bool ManualVoyageEnt { get; set; }
     public KeyAccountManagerCode? KeyAccountManagerCode { get; set; }
     public string NationalKeyAccountManagerCode { get; set; }
     public object ContractTerminateTypeCode { get; set; }
     public object ContractTerminateTypeName { get; set; }
     public SpectraCoaType? SpectraCoaType { get; set; }
     public bool HasContractFree { get; set; }
     public bool HasSatisTahminEkKatilim { get; set; }
     public TypeEnum Type { get; set; }
     public object HashKey { get; set; }
     public long? AsmCode { get; set; }
     public string AsmTitle { get; set; }
     public bool IsBid { get; set; }
     public bool IadesizlikPrimi { get; set; }
     public bool HasPfkb { get; set; }
     public bool HasPesinBed { get; set; }
     public bool HasZamanBed { get; set; }
     public long Time { get; set; }
     public long Time1 { get; set; }
     public bool StampDuty { get; set; }
     public long ItemCustomerType { get; set; }
     public bool HasUda { get; set; }
     public bool HasBailText { get; set; }
     public bool IsCiroPrimFaturaMerkez { get; set; }
     public bool FailContract { get; set; }
     public long? NewMasterOutletNumber { get; set; }
     public string NewMasterOutletName { get; set; }
     public long IsChangeMasterOutlet { get; set; }
     public bool NoContractFor3Month { get; set; }
 }
var url = await _ContractService.GetContractList();

var json = url.Content.Items;

ContractList list= JsonConvert.DeserializeObject<ContractList>(json);

Debug.WriteLine(list.ContractNumber);
Debug.WriteLine(list.StartDate.ToString());

How to add Additional mtouch arguments?

$
0
0

Hello,
I need to add two additional arguments under --optimize in "Additional mtouch arguments" for iOS...how do I do it?

  • Option A: --optimize=-remove-dynamic-registrar --optimize=experimental-xforms-product-type
  • Option B: --optimize=-remove-dynamic-registrar,experimental-xforms-product-type

Which one is correct, if any? Thanks

REST API

$
0
0

Could anyone help me?

I have my app connected to a REST API, but I can't seem to figure out how to get one item. I try to do this using the refit library.
So far I've got:

[Get("/Database/{num}/Likes")]
Task<int> GetLikes(int num);

Which is in an API.cs interface

And in my MainPage.xaml.cs, I've got:

var nsAPI = RestService.For<API>("[LINK TO MY API]");
currentLikes = await nsAPI.GetLikes(Convert.ToInt16(swipeCardView.Id));

When I run the app, I got the error "Specified cast is not valid."

Viewing all 79144 articles
Browse latest View live