Quantcast
Viewing all 81910 articles
Browse latest View live

Ajouter image in xamarin forms Drawable in android but not showing in ios

Image may be NSFW.
Clik here to view.


HttpClient PostAsync doesn't return anything

I have a PostAsync that doesn't return anything and doesn't continue code execution afterwards. I get no error but nothing happens when it reaches PostAsync. My code:

        public async System.Threading.Tasks.Task<HttpResponseMessage> LoginAsync(string name, string name2, int sourceid)
        {
            var client = InitiateHttpClient("");
            var json = JsonConvert.SerializeObject(new
            {
                name = name,
                name2 = name2,
                sourceid = sourceid,
            });
            var data = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await client.PostAsync("myRequestUri", data).ConfigureAwait(false);
            return response;
        }

            HttpResponseMessage httpResponseMessage = await login.LoginAsync(Text1, Text2, Source);

EDIT:

After several seconds (possibly 1-2 minutes) I get Exception Unhandled
System.Threading.Tasks.TaskCanceledException: 'The operation was canceled.'

Trouble displaying html in webview with javascript

Hello, I am trying to request to payment gateway server using following code

using (HttpClient client = new HttpClient())
{
FormUrlEncodedContent content = new FormUrlEncodedContent(request);
var response = await client.PostAsync(url, content);
responseString = await response.Content.ReadAsStringAsync();
}

I am getting successful response from payment gateway and I am rendering response string to webview like this..

GatewaySource = new HtmlWebViewSource
{
Html = System.Web.HttpUtility.HtmlDecode(responseString)
};

response have html with loads of Javascript code but javascript is not working/injecting thus I can't go ahead with payment cycle.

Please find attached response file from payment gateway which I ain't able to display properly.

Xamarin.Forms android app exit alert

I want when user press 'back button' on android device to exit my app, there is a alert dialog shown to ask user 'Do you want to exit ? (Yes, No)'.

https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.application.pagedisappearing?view=xamarin-forms
I found 'Application.PageDisappearing Event', but I don't know how to write the code.
I have never write the code to work with Event variable.

I need to do the exit alert because my app have TcpClient connection, if the app exit the connection will be disconnect.
I want user use 'home button' to let my app go background, that will be keep the connection alive.

How do to REST API with xmarin.forms

Hi there

I have used RestSharp and wrapped an api into a nice NET Standard library
the library takes username, password and platform as arguments and then api outputs api key which library uses internally it also had data models in it

now it works fine, but I don't know how to integrate it into Xmarin.Forms, where to initiate it to be able to acsess its methods and its data from every xmarin.forms subpage (I am using a AppShell)

if we start with Shell Template that visual studio 2019 provides

should I initiate my API in AppShell.xaml.cs or in App.xaml.cs
but then if I do that in there how would I acsess it in for instance AboutPage View Model (I can make it static but this doesn't seem right and it wierd you have to call AppShell.myApi everytime you want to use an api)?

How would I access it in Xmarin.Android portion (I could use MessageCenter(but I can only call void methods with this I cannot(or don't know how) return data) or I could create some static classes in Xmarin.Forms portion, but I don't know if it is the right approach)

what is the best way to handle exeptions (for now my library only throws Exeption with message: throw new Exception("Message Here"))
API has errors like this:

200 - Request successful. More information is returned in json object. Object schema depends on method.
201 - Request successful. No result returned.
400 - Error occurred. Additional information provided in json response (ErrorResponse format: more info below)
401 - Authentication failure. There are two possible reasons: disabled API access or invalid ApiKey provided
403 - Access forbidden
404 - Invalid method URL
405 - HTTP method not allowed, please verify HTTP method of the request
429 - Too many requests in a given amount of time. API limits are 20 requests/second, 1500 requests/hour, 10000 requests/day
5xx - Something wrong happened in Calamari backend. Please wait a while and repeat your request. If error still occurs, drop us a line.

If status 4xx is returned, you can read additional information from returned json object.
{
"message": string,
"code": string,
"field": string
}

message - Human readable error explanation.
code - Error code. Possible value depends on method but there is few common error codes.
field - Which field of payload object caused error. NULL when error is not related to particular field

What is the best aproach to throw appropriate exeption for this, at the end I would like to show an alert to the user if exeption accures, so my library would trow 500Exeption for instance and user would get an error

how would I do this globally, so I don't need to wrap every button in try/catch block

All theese are more of a design questions that bother me and I don't know where to find anwsers to them, as I never saw an example with Xmarin.Forms and REST api that takes username/password api then sends api key which app uses in all subsequent API requests

Hopefully someone can give me some advice on all this, (particulary how to handle exeption and inform the user and where in the project to construct the api so I can easly acsess it from all subpages)

Thannks for Anwsering and Best Regards

Integrating login page in Master Detail Page Xmarin.Forms example

Hi there
I created Master-Detail example app when creating new Xmarin.Forms project

but then I wanted to integrate this login screen: mallibone.com/post/creating-a-login-screen-with-xamarinforms

Now He is using A simple Navigation Service for Xamarin.Forms: mallibone.com/post/a-simple-navigation-service-for-xamarinforms
to show login page and navigate

now the problem is I cannot seem to integrate this into my app

now in the xmarin.forms master-detail page example, main page(app.xaml.cs) it started like this: MainPage = new MainPage();

but the SimpleNavigationService requires the page to be started like this:

_navigationService.Configure(PageNames.LoginPage, typeof(Views.LoginPage));
_navigationService.Configure(PageNames.MainPage, typeof(Views.MainPage));
MainPage = _navigationService.SetRootPage(nameof(Views.MainPage));

if I do that then Hambuger menu navigation doesn't work (I get System.NullReferenceException: 'Object reference not set to an instance of an object.', but it doesn't show where) any more and app looks weird (cannot post picture, but there are 2 hambuerger menu icons it looks like MainPage in MainPage)
Image may be NSFW.
Clik here to view.

Hopefully someone can tell me how I can use A simple Navigation Service for Xamarin.Forms with Master-Detail page (cuz it looks like a neat library)

Thanks for Anwsering and Best Regards

Usage of ImageSource.FromFile for Android Assets

Hi,

I just updated Xamarin.Forms, so I'm using the current (Xamarin.Forms.1.0.6197).

I have the following code:

public string BuildFlagPath(string flagName) {
    return String.Format("{0}{1}.png", Device.OnPlatform("Flags/", "Flags/", "Assets/Flags/"), flagName);
}

// For the image source
Source = ImageSource.FromFile(BuildFlagPath(_currency));

This is working well for iOS and Windows Phone, but I can't get it working for Android.

Just for the complete picture:

  • Assets are a bunch of png files
  • Windows Phone

    • Assets are in "/Assets/Flags/" folder
    • Build action: Content
    • Copy to output directory: always
  • iOS

    • Assets are in "/Resources/Flags/" folder
    • Build action: BundleResource
    • Copy to output directory: Do not copy
  • Android

    • Assets are in "/Assets/Flags/" folder
    • Build action: AndroidAsset
    • Copy to output directory: Do not copy

What am I missing here to get it working?

responsive control

hi
Image may be NSFW.
Clik here to view.

Image may be NSFW.
Clik here to view.

2 item in mobile
tablet 3 or 4

how responsive control in page Image may be NSFW.
Clik here to view.
:/


search inside picker xamarin forms (Custom Renderer)

i need filter picker any idea ?

i try Xfx.Controls negut but not workin for me

PushModal doesn't seem to be working as it used to iOS

I have been using Navigation.PushModalAsync for sometime, however recently i have noticed a change where the user can swipe down to dismiss the page - which is not the behaviour i need for the flow I am implementing.

Not sure if this is a change in iOS or Xamarin Forms but how can i get the previous behaviour back (i.e. user cannot dismiss the page by swiping away)?

I've seen this behaviour on iPhone 8 & iPhone 11 iOS 13.3 simulator.

Visual Studio Community 2019 for Mac
Version 8.3.11 (build 1)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)
Xamarin.iOS
Version: 13.6.0.12 (Visual Studio Community)

Support to convert the HTML to PDF in Xamarin Forms

Support to convert the HTML to PDF in Xamarin Forms

open street map tile display method

I am a Xamarin beginner

I want to display an open street map as a tile, but it doesn't work

In the source below, only one image is displayed

Please tell me how to display tiles


[Obsolete]
private async void  Pic()
{

    for (int i = 1; i <= 10; i++)
    {
        string url = "";

        url = "http://c.tile.openstreetmap.org/" + 18 + "/" + (233891 + i) + "/" + 100481 + ".png"

        try
        {
            using (Stream stream = await httpClient.GetStreamAsync(url))
            using (MemoryStream memStream = new MemoryStream())
            {
                await stream.CopyToAsync(memStream);
                memStream.Seek(0, SeekOrigin.Begin);
                helloBitmap = SKBitmap.Decode(memStream);
            }

            using (SKCanvas bitmapCanvas = new SKCanvas(helloBitmap))
            {
                bitmapCanvas.DrawBitmap(helloBitmap,i * 256,0,null);
            }
        }
        catch
        {
        }
    }

    SKCanvasView canvasView = new SKCanvasView();
    canvasView.PaintSurface += OnCanvasViewPaintSurface;
    Content = canvasView;

}

[Obsolete]
private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{

    SKImageInfo info = args.Info;
    SKSurface surface = args.Surface;
    SKCanvas canvas = surface.Canvas;

    using (surface = SKSurface.Create(width: 1000, height: 1000, SKImageInfo.PlatformColorType, SKAlphaType.Premul))
    {
        canvas.DrawBitmap(helloBitmap, 256, 256, null);

    }           
}

Why ImageSource.FromFile() doesn't work on UWP ?

    public static readonly BindableProperty ImageProperty =
        BindableProperty.Create(propertyName: nameof(Image),
                                returnType: typeof(string),
                                declaringType: typeof(ProductWithDetailsCustomControl),
                                defaultValue: default(string),
                                defaultBindingMode: BindingMode.TwoWay,
                                propertyChanged: (bindable, oldValue, newValue) =>
                                {
                                    if (bindable is ProductWithDetailsCustomControl x &&
                                       newValue is string stringValue)
                                    {
                                        x.ItemImage.Source = ImageSource.FromFile(stringValue);
                                    }
                                });

    public string Image
    {
        get { return (string)GetValue(ImageProperty); }
        set { SetValue(ImageProperty, value); }
    }

The stringValue is = C:\Users\salar\Desktop\New folder\MilkTea.png and its exist

This is my custom property to bind the image source to my ItemImage, and I want to fetch the image from a certain path to set as an image source using ImageSource.FromFile();

I'm using UWP platform and my idea is to save all the images in a certain folder and fetch it. Is there any way how to set the image from the file to ImageSource? or I have missing steps to reach my goal.?

TabbedPage with Bottombar

Hello,

is it possible to make a Bottombar on a TabbedPage tag instead on each Contentpage?

I have different Contentpages, the amount varies depending on the Task which coming in.
Problem the Bottombar has Bindings with Actions which will be split if I add on each individual ContentPage.

Image may be NSFW.
Clik here to view.

Custom Picker not initializing

Hello, everyone!

I need some help. I have spent all day trying to make a "simple" custom control, just a Picker with a down arrow button. I could put a normal picker and a button on a StackLayout, and add to the onClick button event a simple myPicker.Focus()... but I want to do things right, and also learning a bit more on how to do custom controls, bindable properties, etc.

I attached the code of my control, just a view and its code behind. I'm still working on it, fixing errors as long as I change all Pickers from my project with this one.
Right now, the problem I have is that I have the "ArrowPicker" in my page like this:

<customControls:ArrowPickerView x:Name="pkr_Marca" HorizontalOptions="FillAndExpand" ToolsBackgroundColor="{x:Static statics:Palette._MainColor}" TextColor="{x:Static statics:Palette._MainColorDark}" ItemsSource="{Binding MarcasList}" ItemDisplayBinding="{Binding Name}" SelectedIndex="{Binding MarcaSelected, Mode=TwoWay}" IsEnabled="{Binding IsNewOrder}" ArrowIconColor="Dark"/>

And I have this method to initialize values in ViewModel:

```async Task ExecuteLoadMarcasListCommand(string _cardCode = null)
{
int pos;

        IsBusy = true;
        LoadMarcasListCommand.ChangeCanExecute();

        //Getting Marcas List
        tempList = await WebApiMarcasData.GetMarcasList();

        if (tempList != null)
        {

            //tempList.Add(new BaseModel() { Id = "222", Name = "Test2" });
            //tempList.Add(new BaseModel() { Id = "333", Name = "Test3" });
            //tempList.Add(new BaseModel() { Id = "444", Name = "Test4" });
            MarcasList = new ObservableCollection<BaseModel>(tempList); //if tempList is null, it creates an exception
            if  (!string.IsNullOrWhiteSpace(Order.marcaId))
            {
                pos = MarcasList.IndexOf(MarcasList.FirstOrDefault(x => x.Id == Order.marcaId));
                if (pos >= 0)
                    MarcaSelected = pos;
                else
                    MarcaSelected = 0;
            }
            else
                MarcaSelected = 0;

        }
        else
            if (MarcasList != null)
            MarcasList.Clear();

        IsBusy = false;
        LoadMarcasListCommand.ChangeCanExecute();
    }```

Well, I have a list from my WebApi with one element, so when I execute the IndexOf function, there is a match with the first element of the list, and pos is equal to 0. But when MarcaSelected is assigned with a zero, nothing happens. The inner Picker don't raise an event, it don't show the "Name" field of the first value, nothing, is blank.
However, I can tap it, select the element of the list, and then it shows, but for some reason, is not initialized by code. And using just a Picker is working fine.

I traced the code, and it sets MarcaSelected from -1 to 0 in the page initialization, then load the list with this code, but it does nothing when "MarcaSelected = pos". Maybe because is the same value?

I'm sure you'll find more errors in my code (I wasn't able to make ItemDisplayBindingProperty work properly, it only shown the Model class name on the list, instead the field I wanted... I mean "Models.BaseModel" instead "Nuka Cola", or to overwrite IsEnabled), and I will appreciate any suggestions to fix it, but right now, I need to fix that initialization problem to keep working.

If you need more info, just ask. Thank you.


Files required for app gets deleted from LocalStorage on popping a navigation page

Hi,

I am working on an app which uses "WKWebview"(ios customrenderer) to play embedded YouTube videos.
It has two navigation pages Page-1 and Page-2.
Page-1 is root page.

Page-1 contains : Wkwebview (To show advertisement video and this link always remains same) and ListView-1 (category links)
Page-2 contains : Wkwebview (To show videos) and ListView-2 (Actual video links)

It work like:

  1. I am using Same WkWebview CustomRendere for both Pages.

  2. Working on Simulator with ios version 12.0

  3. When i visit page-1 it loads advertisement video and populate category links in ListView-1 . (Here it automatically stores https_www.youtube.com_0.localstorage, https_www.youtube.com_0.localstorage-wal and https_www.youtube.com_0.localstorage-shm) in local storage.

  4. On clicking any item in ListView-1 it uses Navigation.PushAsync() to load Page-2 and shows corresponding Video links in ListView-2 and a video in Wkwebview corresponding to first video in ListView-2. And then we can choose any video and it displays quit well. (Here no we files are created in local storage, as they use existing files).

Problem:

  1. On clicking the Back button of Page-2 following Message appears three times. (For https_www.youtube.com_0.localstorage, https_www.youtube.com_0.localstorage-wal and https_www.youtube.com_0.localstorage-shm)

[logging] BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked while in use: /Users/ZZZ/Library/Developer/CoreSimulator/Devices/5BA-702-44C-9B-4465FA982/data/Containers/Data/Application/A1F-B71-1FA-A-D43BA9C/Library/WebKit/com.companyname.ZZZ/WebsiteData/LocalStorage/https_www.youtube.com_0.localstorage

When i looked in LocalStorage the files were actually deleted.

This happens only once when we navigate from Page-1 to page-2 and back for first time, if we perform the same repeatedly no message appears (even though files are still getting deleted.)

What Should i do?

Managing dependencies of a external SDK

Hi!

I've started a process of building a java binding on top of a SDK provided for us by one of our partners. I'm struggling a bit but little by little I'm managing to make progress. However, the point of this post is not the java binding, but one curious fact that made me wonder about managing dependencies of a SDK, be it one provided for us or one that we have to build ourselves.

The curious fact is: I'm having to import some dependencies that are specific for Android on the front-end application that is consuming the SDK. Why is this happening? For example, in order to run a method from the SDK, the compiler (Visual Studio) asks me to import GoogleGson, Kotlin, Koin, etc. Which are dependencies specific for Android. Shouldn't the SDK wrap them within itself without forcing the application to import them as well? If that situation is to be expected, why does that happen?

I'm pretty sure this is something more in line with the concept of managing dependencies than Java Bindings specifically, which is why I'm posting here. Any light on this subject would be really appreciated.

Set accessibility focus after button click

Hi all,

I am trying to figure out how one would get the accessibility cursor to change focus to an element after a button click. For example when I press a button in my app that is hiding content I want to focus on those new elements that have recently become visible after a button click. Im aware of tab index in XF 4.0, but my understanding of TabIndex is that it only sets the order in which the focus is supposed to follow. I want to set the accessibility cursor on an element that has just been made visible to the user, and then set the order on those new elements. Is anyone aware of how I could accomplish this?

Thanks!

Issue: InstallFailedException

I am currently having an issue with running my Xamarin.Forms app on my mobile device whether it be emulated or my physical test device.
I am on Visual Studio 2019 and it is a new app project and I have had it running before but usually after the first run it does not work again after that if it did.
The error code is as follows:

ADB0010: Mono.AndroidTools.InstallFailedException: Failure [INSTALL_FAILED_INVALID_APK: Package couldn't be installed in /data/app/com.companyname.appname-w4jR_g7Ki-eDsfg24hSJUA==: Package /data/app/com.companyname.appname-w4jR_g7Ki-eDsfg24hSJUA==/base.apk code is missing]
   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in E:\A\_work\254\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:line 341
   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass95_0.<InstallPackage>b__0(Task`1 t) in E:\A\_work\254\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:line 753
   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext() in E:\A\_work\254\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 187
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext() in E:\A\_work\254\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 203
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<InstallPackage>d__112.MoveNext() in E:\A\_work\254\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 414
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__106.MoveNext() in E:\A\_work\254\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 217
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__104.MoveNext() in E:\A\_work\254\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 119

I have tried many things including:
Repairing the SDK
Uninstalling Visual Studio, Android Studio, Android SDK and then re-installing them

Version bumping for for DevOps builds

I used to use a script to
1. Check out appmanifest.xml / info.plist
2. Add +1 to the versioncode
3. Check the file back in again

Now we moved to Azure devops and I'm redoing some of the build-strategies. One thing I came across was James Montemagnos Mobile App Tasks.

From what I can tell, this tasks does not use the old version+1. Instead it uses $Build.BuildId from Azure DevOps (at least as it's example). Nor does it check out/in anything.

Just want to check with the rest of you. What strategy do you use? Checking in the new VersionCode or not?

Viewing all 81910 articles
Browse latest View live


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