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

How to navigate to another app


How can i do to show an entry like a textbox

$
0
0

When i put on app an entry it seems line only. My client want to show like a textbox(a box to text and not a line). Is there how to do?

Facing issue in HTTPClient post method in Xamarin forms (Android)

$
0
0

I'm facing issue with http call.
Error Message is : httpclient postasync an error occurred while sending the request

`public TResult PostAPI(string url, T reqparams, List<KeyValuePair<string, string>> formParameters = null, string jsonString = "", List<KeyValuePair<string, string>> headers = null)
{
HttpContent contentPost = null;
if (headers != null)
{
AddHeaders(headers);
}
if (formParameters != null)
{
var formContent = new FormUrlEncodedContent(formParameters);
contentPost = formContent;
}
else if (!string.IsNullOrEmpty(jsonString))
{
var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
contentPost = content;
}
string s = JsonConvert.SerializeObject(reqparams);
var contents = new StringContent(s, Encoding.UTF8, "application/json");
contentPost = contents;

        //client. = 3000;
        var response = client.PostAsync(url, contentPost).Result; //Task.Run(() => client.PostAsync(url, contentPost)).Result;

        IEnumerable<string> responseHeaders;
        response.Headers.TryGetValues("Authorization", out responseHeaders);

        if (responseHeaders != null && responseHeaders.Any())
        {
            AccessToken = responseHeaders.Select(x => x).FirstOrDefault();
        }

        var apiResult = response.Content.ReadAsStringAsync().Result;
        var result = JsonConvert.DeserializeObject<TResult>(apiResult);
        return result;
    }

`

below is Inner exceptions

at System.Net.Http.HttpClientHandler+d__63.MoveNext () [0x004ab] in <7736395a6c71409691a34accfc621095>:0 --- 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) [0x0003e] 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.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Net.Http.HttpClient+d__49.MoveNext () [0x000ca] in <7736395a6c71409691a34accfc621095>:0

Hot to maintain aspect ratio of custom View?

$
0
0

Hi,
I'm trying to maintain aspect ratio of custom View, i.e. to shrink proportionally if there is less space than requested.

I have tried to override OnMeasure that returns corrected SizeRequest that still have the same aspect ratio but this seems to have no effect at all.

Here is sample View:

    public class AspectBoxView : BoxView
    {
        protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) {
            var resizeW = widthConstraint / WidthRequest;
            var resizeH = heightConstraint / HeightRequest;
            var resize = Math.Min(resizeW, resizeH);

            var width = WidthRequest * resize;
            var height = HeightRequest * resize;

            Debug.WriteLine($"witdh={width}, height={height}");    // this logs "witdh=50, height=50" for second box
            return new SizeRequest(new Size(width, height));
        }
    }

XAML:

    <StackLayout Orientation="Vertical" Spacing="20" VerticalOptions="Start">

        <Grid BackgroundColor="Yellow" HeightRequest="120">
            <local:AspectBoxView WidthRequest="100" HeightRequest="100" BackgroundColor="Green" 
                                 HorizontalOptions="Center" VerticalOptions="Center" />
        </Grid>

        <Grid BackgroundColor="Yellow" HeightRequest="50">
            <local:AspectBoxView WidthRequest="100" HeightRequest="100" BackgroundColor="Green"
                                 HorizontalOptions="Center" VerticalOptions="Center" />
        </Grid>

    </StackLayout>

Unfortunately I'm not allowed to post screenshot but second AspectBoxView renders as 100 x 50. I have expected second box to be 50 x 50 (which is logged).

How could I force View to maintain same aspect ratio, regardles of size?

Thanks.

Custom listview items

$
0
0

Hi there,
i'm working together with two friends on a school project.
We have thought on a design for the applications that we would like to build. Our problem is that we don't really know how to accomplish it.
I wanted to add a image to this post but xamarin won't let me because i haven't been on this forum long enough. So i'll try to explain it.
We would like to style our listview in a way that each item is a trapezium shape. There is a margin on every side so that you can see the background of the app. We also want that every even item indexed in our source list has the reversed trapezium shape of the uneven item index.
Anyone here that could help us out?

Kind regards,
Lucas
student @ Howest (Belgium)

Access UI threads dispatcher from Xamarin.Forms ContentPage

$
0
0

Can anyone recommend the best way to schedule some work on the UI threads dispatcher when you're within a ContentPage. We don't seem to have access to the being invoke method?

Thanks.

Xamarin.Forms.Navigation

$
0
0

Xamarin.Forms.Navigation: NuGet Package for Xamarin.Forms, mainly developed for MVVM Apps,

Source code + Sample: www.github.com/medalinouira/Xamarin.Forms.Navigation
NuGet Package Url: www.nuget.org/packages/Xamarin.Forms.Navigation/
Android Demo: play.google.com/store/apps/details?id=xamarin.forms.navigation

Many thanks in advance for your feedback !

Mvvm Navigation - PushAsync does not hit Viewmodel Constructor

$
0
0

I am using mvvm and I Navigate from page to page with

await App.Current.MainPage.Navigation.PushAsync(new page2(), true);

Lets say I want to navigate from page1 to page2.

When I use the back button, in order to navigate back from page2, the viewmodel constructor of page1 is not executed. Is that the expected behaviour?
In the viewmodel I do some binding and when I navigate back those bindings are not made so I get the previous state of the page. Can you suggest me any way of activating viewmodel functionality from back button ?


Creating a Sync Database makes Visual Studio hang and then exit code, while in a try catch!

$
0
0

I am trying to integrate a simple Sync Database for an Azure easytable. I am following many of James Montemagno tutorial/example projects. like this one
https://github.com/jamesmontemagno/app-coffeesync/blob/master/CoffeeApp.Shared/Model/Azure/AzureService.cs
and this one
image
I am so stumped. I have been working on this for days and tried so much, and created new problems that took a lot of time to fix. But I am finally fully stuck. I don't know what to do now :disappointed:

When I run this in Debug and step through everything Visual Studio Hangs for about 6 seconds and then it exits the code and the Output says
"Resolved pending breakpoint at 'ChatStorageAzureService.cs:120,1' to void CFFA.Services.ChatStorageAzureService.d__15.MoveNext () [0x000d6].
Thread finished: #22
Thread finished: #24
Thread finished: #23
Thread finished: #25
The thread 0x16 has exited with code 0 (0x0).
The thread 0x18 has exited with code 0 (0x0).
The thread 0x17 has exited with code 0 (0x0).
The thread 0x19 has exited with code 0 (0x0)."
And then the app on my phone is frozen and I have to Stop the debug.
This all happens when I just run this line
var path = "syncstore.db";

How in the world is just assign a string var going to crash the program!?!?! Oh, and on top of all this, that code block is in a freaking try catch! But no exception is ever thrown :disappointed:
I am assuming another part of the code is breaking it. But I am trying to follow this simple tut to the t. Now I have to make it work inside my app so I have to change parts, but stuff that should not affect the overall function.
I also could not create a Singleton of the ChatStorageAzureService with Dependency like the tut tells me to because of this issue.https://forums.xamarin.com/discussion/comment/312753#Comment_312753
But I don't think that should be an issue as I only create ChatStorageAzureService one time when I run this code.
Ideas?
Here is the code block that breaks

public async Task InitializeAsync()
{
if (client?.SyncContext?.IsInitialized ?? false)
return;

        var appUrl = "http://MY-SITE.azurewebsites.net";
        try
        {
            client = new MobileServiceClient(appUrl);

            var path = "syncstore.db";

            var store = new MobileServiceSQLiteStore(path);

            store.DefineTable<MessageViewModel>();

            await client.SyncContext.InitializeAsync(store);

            chatTable = client.GetSyncTable<MessageViewModel>();
        }
        catch (Exception e)
        {
            Debug.WriteLine("Exception thrown in Initialize: " + e);
            throw;
        }
    }

Creating a new MobileServiceClient() freezes VS and Android app.

$
0
0

I created a different question but it has gotten convoluted over time as I gained more insight so here is a new clean post.

So I am trying to connect to a easy table Azure service. I have followed James's tuts and had them work correctly. But now I am integrating them into my app and I broked it... when I hit the line
client = new MobileServiceClient(appUrl);
I can step to the next line
var path = "syncstore.db";
But then VS hangs for around 10 seconds and comes back and the Android app is frozen indefinitely. I have changed the order of the lines and it always freezes on the line after client = new MobileServiceClient(appUrl); So I am assuming thats the culpurit
I have this in a try catch, but it does not throw an exception.
I tested the server side with Postman calls and those work fine, both Posts and Gets.
I recently learned how to debug with Azure cloud services. But I am not getting any call to hit the server from the mobile app. Its like it hits a blackhole when MobileServiceClient() is invoked.

Here is the method in question:

public async Task InitializeAsync()
{
if (client?.SyncContext?.IsInitialized ?? false)
return;

        var appUrl = "http://chattestjbapp.azurewebsites.net/";
        try
        {
            client = new MobileServiceClient(appUrl);

            var path = "syncstore.db";

            var store = new MobileServiceSQLiteStore(path);

            store.DefineTable<MessageViewModel>();

            await client.SyncContext.InitializeAsync(store);

            chatTable = client.GetSyncTable<MessageViewModel>();
        }
        catch (Exception e)
        {
            Debug.WriteLine("Exception thrown in Initialize: " + e);
            Debug.WriteLine("ExceptionMessage thrown in Initialize: " + e.Message);
            throw;
        }

}

That method has been called a multitude of different ways see my old post for more details

Cross platform hamburger menu (migrating from UWP project)

$
0
0

I have an app I want to convert to Xamarin.Forms, and the app is written for WIndows 10 UWP. I designed the hamburger menu according to this sample

github (dot) com/Microsoft/Windows-universal-samples/blob/master/Samples/XamlNavigation/cs/AppShell.xaml.cs

And my question is, what is the equivalent way (if any) to replicate this style of menu in Xamarin.Forms
I'm guessing a lot of that code can't be directly transferred to Xamarin (PCL) because is uses Windows specific references.

EDIT:
I did find several examples that use master details page such as this one and was wondering if that is the way to go.
wolfprogrammer (dot) com/2016/09/02/creating-a-hamburger-menu-in-xamarin-forms/

How to force the Detail page to move right with the Master page on iPad in Xamarin.forms

$
0
0

When using an iPhone, the Detail page automatically moves to the right with the Master page when the hamburger/menu icon (☰) is clicked.

Before clicked:
https://i.stack.imgur.com/yGRelm.png

After clicked: (As you can see, the entire Detail page moves with the Master)
https://i.stack.imgur.com/CtATnm.png

However with an iPad, when you click the Hamburger icon, the Master page moves right, but goes on top of the Detail page (and so the Detail page doesn't move right with it)

Before clicked
https://i.stack.imgur.com/tFG7Zm.png

After clicked (As you can see here, the Detail page does not move right with the Master page. This can be identified by looking at the "Home" Title, and how it does not change position from before to after)
https://i.stack.imgur.com/5Y2rTm.png

Question My question would be how to recreate this effect (experienced on iPhone) on iPad. The main reason why I wish to do this, is because of the ShadowEffect I have attached to the NavigationPage.Appearing.

This moves with the navPage, and so on iPads, it is hidden. I also use the MasterBehavior.Popover enum for the MasterBehavior property.

Thanks for your time, Daniel

No xamarin.forms portable category at creating new project

$
0
0

There is no category Xamarin.forms portable :(
I've already download include xamarin package and also checked whether there is no update or installation that I need to use for Xamarin.
In other words, I can't find any flaw in installing or updating Xamarin. What should I do? Please help this beginner

My visual studio version is 2017 15.5.3

Setting shadow on detail page in MasterDetailPage

$
0
0

I am trying to recreate this UI.

Screenshot

I'm using a MasterDetailPage. In the existing app the background of the master page and the detail page are white. To separate them, the detail page has a shadow around it.

The detail page also needs to be a NavigationPage.

I noticed the Frame has a HasShadow property.

If I make my detail page a ContentPage with a Frame I can get the shadow effect. However, I can't put a NavigationPage as a child of a Frame.

If I make my detail page a NavigationPage, any Frame in it doesn't also surround the titlebar.

Any suggestions?

OnIdiom not picked up by Designer

$
0
0

Hi I am trying to set the width and height of a grid with OnIdiom like this:

<Grid x:Name="myUglyGrid" BackgroundColor="Aqua">
    <Grid.WidthRequest>
        <OnIdiom x:TypeArguments="x:Double" Phone="46" Tablet="1"/>
    </Grid.WidthRequest>
    <Grid.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double" Phone="46" Tablet="1"/>
    </Grid.HeightRequest>
</Grid>

If I run this code on a device iPad or iPhone, then the different sizes for Phone or Tables are correct, but the designer in Visual Studio Mac (7.3.2) does not show this difference, it only shows the Phone size. Is this a know issue or am I doing something wrong?

Thanks!


Tabbed page within a tabbed page after a grid

$
0
0

Hello,
Im new to xamarin, and I have been struggling with a tabbed page that has a tabbed page inside it. The problem is that that tabbed page should be in the second row(I want a grid that seperates the content into two parts).

What I am aiming for is something like this in picture, except the top navigation is also a tabbed page. Is there any good way to do this, or is this not recommended?

What does it mean when the Xamarin emulator hangs and does not show phone/app ?

$
0
0

When I run my app in Visual Studio I use Android 7.1 emulator available but the phone does not appear when the simulator comes up.
The output window just shows waiting on emulator.
The warning messages says my Target Version of 8.0 from Xamarin.forms view dll is 8.0 but my Target Framework version of my project is on 7.1.
I don't see how to update that in Visual Studio interface. When I change it in the cproj file it reverts back to 7.1 when I re-run.
Also, how do I get other emulators in the list to use ?

Getting Exception When trying to bind pins in xamarin forms using xamarin.forms.googlemaps.bindings

native map is throwing null exception in iOS custom renderer

$
0
0

Im trying to custom renderer the map in iOS and all Im getting is null reference exception from line(var nativeMap = Control as MKMapView) saying that native map is null.Please can anyone one give me a good solution for this and below is my code, The map which I use is google map.

[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]

namespace MapOverlay.iOS
{
public class CustomMapRenderer : MapRenderer
{
MKPolylineRenderer polylineRenderer;
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);

        if (e.OldElement != null) {
            var nativeMap = Control as MKMapView;
            if (nativeMap != null) {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
                nativeMap.OverlayRenderer = null;
                polylineRenderer = null;
            }
        }

        if (e.NewElement != null) {
            var formsMap = (CustomMap)e.NewElement;
            var nativeMap = Control as MKMapView;
            nativeMap.OverlayRenderer = GetOverlayRenderer;

            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];
            int index = 0;
            foreach(var position in formsMap.RouteCoordinates)
            {
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }

            var routeOverlay = MKPolyline.FromCoordinates(coords);
            nativeMap.AddOverlay(routeOverlay);
        }
    }
}

}

IDE0006 Error encountered while Loading The Project

$
0
0

IDE0006 Error encountered while Loading The Project

Viewing all 58056 articles
Browse latest View live


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