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

Native Android library in cross-platform mobile app

$
0
0

Hi all,

we are developing a mobile application for Android and iOS and we have chosen the Xamarin.Forms platform to create our app in a cross-platform manner. This app shall use external functions provided to us as external library. Currently, this library is available for Android as native Android library (Android Library, written in Java and compiled as .aar file). The external library also includes a sample Android app written in Java as well in order to verify that the library is working and in order to demonstrate the library. The library plus sample app can be opened in Android Studio IDE and can be tested nicely. Soon, our partner will provide an iOS version of this library, probably as native iOS library.

Binding the library as described in https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-an-aar/ works well which means the imported namespace, classes and methods of the library are nicely accessible in our Xamarin project.

Now, we are facing the following problem: It is required that the App class (which is the application instance for the compiled Android app to which all activities refer to and which must be a sub-class of android.app.Application) must inherit 'MyApplication' which is part of the library. In other words, 'MyApplication' extends android.app.Application and implements some interface which is part of the library as well and 'App' (our Android application instance) must extend 'MyApplication'. Otherwise, the library functions do not properly work. But how to make this work in a Xamarin cross-platform application? In our Xamarin cross-platform project, there can be defined a custom application class inheriting from xamarin.forms.application but it is not possible to let this class inherit from 'MyApplication' because latter is Android-only but the cross-platform application class should be platform-independent of course. Otherwise, within the Android project of our solution there is a class MainActivity.cs which calls LoadApplication() to which I can pass a xamarin.forms.application object but how to pass my Android app class extending android.app.Application? Are xamarin.forms.application and android.app.Application somehow convertable? Also, within OnCreate() within the MainActivity.cs, it is possible to get the current application instance (which is in fact of type android.app.Application) but is it possible to set it?

Thank you all very much in advance for some inputs.


The name 'InnerExceptionCount' does not exist in the current context

$
0
0

I am getting this error in a UWP project. It is getting caught in the unhanded exception handler when I close my application. I cannot figure out where this is happening. I have even removed most all logic from the app and it still crashes on close. Ideas?

  • $exception Count = error CS0103: The name 'InnerExceptionCount' does not exist in the current context System.AggregateException

Trace:
There was an error deserializing the object of type System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]. The data at the root level is invalid. Line 1, position 1.

at System.Threading.Tasks.Task

1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task
1.get_Result()
at Xamarin.Forms.Application.d__72.MoveNext()
--- 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.Forms.Application.d__50.MoveNext()
--- 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.Forms.Platform.UWP.WindowsBasePage.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__6_0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()

Any ideas how to track this down?

How to get an original image size?

$
0
0

Hi! I have the very basic case, but can't find elegant solution: need to know original image size for layout. But after loading an image to Image view I get -1 value for its width and height.

Here's a code sample, what I'm trying:

var icon = new Image {
    Source = ImageSource.FromFile("icon-edit.png")
};

// This will output -1 values for width and width request
Console.WriteLine("Width={0}, WidthRequest={1}", icon.Width, icon.WidthRequest);

// Adding to relative layout, won't work as expected! Icon's width is calculated as -1.
Children.Add(editIcon,
    Constraint.RelativeToParent((parent) => (parent.Width - icon.Width) / 2),
    Constraint.Constant(10)
);

In the example above icon should be centered horizontally and I could achieve that in some other way. But actually I'll need more sophisticated layout, that's why I need to know image width.

Timeout inside a Task from WCF

$
0
0

After a couple of days messing with WCF Services, i finally managed to create a working Proxy using SLSvcutil and applying Async/Await with Tasks using others advices about wrapping IAsyncResult like this:

 public async Task<tPdtUser> GetUserAsync(string user, string pass)
        {
            return await Task.Factory.FromAsync(((IUser)client.InnerChannel).BeginsPdtUserValidateCredentials,
                                                                       ((IUser)client.InnerChannel).EndsPdtUserValidateCredentials, user, pass, null);

        }

Everything works great now, but i'm having a hard time out figuring out:

How can i validate a Timeout in the request? If no response is given (ex in 5 secs) throw a Timeout Exception?

I've read that i can use Task.WhenAny but as now, if i use this code:

var user = await Repository.GetUserAsync(Username, Password);

Response is a model object (tPdtUser) and not really a Task so im stuck with this

Any help will be greatly appreciated!

How to get an Image to appear screen width and required height in correct aspect ratio

$
0
0

Hi all,
I am trying to display an image at the top of a page. The image is 700 wide by 140 high, and the source is a url.
My page is defined in code. I created a stack layout and added the Image. It displays in the correct aspect ratio, but it doesn't go full width. I manage to get it to go full width, but the height it is calculating is incorrect and so is trimming the top and bottom off the image. Here is some copy and pasted code:

        var source = new UriImageSource
        {
            Uri = new Uri("http://thisismyimageurl"),
            CachingEnabled = false,
        };

        var img = new Image
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Source = source,
            Aspect = Aspect.AspectFill,
        };

        var layout = new StackLayout()
        {
            Spacing = 0,
            Padding = new Thickness(15, 5, 15, 5),
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Orientation = StackOrientation.Vertical,
            Children =
            {
                img,
                // There will be labels, buttons etc following the image
            }
        };

        Content = layout; // EDIT: Added for completeness of this ContentPage example

I have attempted many variations on the layout options for the image and for the stack layout, nothing I do will make the image full width (within the padding of course), and correct height at the same time.

Any ideas on this?

Thanks
John

Linking Assemblies doesn't work in Release

$
0
0

When I build a release Android app, I havae to set Linking=None otherwise the app won't run.
Unfortunately my App size is currently 40M!
Is there something I can do to figure out what assembly is causing this problem?

Xamarin Forms Map error on Andriod after updating Xamarin Forms and Maps to 2.3.3.193

$
0
0

After upgrading Xamarin Forms and Maps to version 2.3.3.193, I now receive the following error on my Andriod app when I attempt to display a map:

{Xamarin.Forms.Platform.Android.ViewRenderer<Xamarin.Forms.Maps.Map,Android.Gms.Maps.MapView>}
{System.MissingMemberException}
Android.Gms.Maps.MapView.get_Map' not found

Any idea what is going on? It worked before the update. Any assistance would be appreciated.

Is it possible to add a banner advertising to my xamarin.forms app?

$
0
0

I could not find a solution for banner implementation. The api from admob does not work for windows phone or uwp. Also i can not add a banner via admob or anything with the pcl project. The banner will be shown always at the bottom of the app. I would like to develop the ui in xaml in the pcl project. I found a discussion with a custom renderer. But it was not a banner advertising. Is it possible to add a advertising in a xamarin.forms app for all plattforms or at least for android and apple?


Tableview inside scrollview

$
0
0

Hi,

I have a tableview inside a scrollview with a label with text under the tableview. I need to be able to let the label scroll with the tableview so it is not i a fixed position. My xaml code works on ios but not on Android.

<ScrollView VerticalOptions="FillAndExpand">
                <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand">
                    <TableView x:Name="NavigationTable" Intent="Menu" BackgroundColor="Transparent" RowHeight="60" VerticalOptions="StartAndExpand">
                        <TableRoot>
                            <TableSection x:Name="MenuTableSection" />
                        </TableRoot>
                    </TableView>
                    <Label x:Name="VersionLabel" Font="{StaticResource NormalFont}" HorizontalOptions="CenterAndExpand" XAlign="Center"/>
                </StackLayout>
            </ScrollView>

How can we change color of Progressbar?

$
0
0

This is my code :

< ProgressBar Progress="0.5" WidthRequest="500" HeightRequest="15" HorizontalOptions="StartAndExpand" / >

Try and background, but I want to change the indicator color line progress

possible bug in NSBundle.MainBundle.ObjectForInfoDictionary() Xamarin Forms version 2.3.4.171-pre1

$
0
0

In my Xamarin Forms app I retrieve the version and build numbers for display. For the iOS build I use the following code to retrieve the build number

NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();

If I leave the build number blank in my Info.plist then "1.0" is returned

However, if I put in a build number, like 5 for example then "5" is returned without the ".0"

It seems trivial but it causes a sneaky problem. My app uses its version number to figure out an API endpoint. If my users are using version 1.2.4 build 4 and then upgrade to version 1.2.4 build 5 everything is fine but once I release version 1.3.0 and leave the build number blank in Info.plist then their apps will crash after the update.

Custom progress bar

$
0
0

Hello!
Does anybody know how to make custom circular progress bar with filling from bottom to top.
Something like on the image

how to make splash screen in xamarin forms for android platform

$
0
0

how to make splash screen in xamarin forms for android platform

Async call through SOAP returning error TargetInvocationException in Xamarin

$
0
0

I have added web service reference to consume the service using WSDL. I am making Async method call to get the response but getting error.

Generated Code

public partial class SoapClient : System.ServiceModel.ClientBase<App1.Data.Soap>, App1.Listing.Soap {
...
}

Client Invocation

SoapClient s = new SoapClient();
s.GetListingsReportCompleted += resultReceived;
s.GetListingsReportAsync(10);

...

public static void resultReceived(Object sender,
                       GetListingsReportCompletedEventArgs e)
{
     e.result --> System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid.
     ...
    ** OR**

    GetListingsReportCompletedEventArgs e : Unknown identifier: GetListingsReportCompletedEventArgs

}

I am getting this in Error : System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid.
Sometime I also get Unknown identifier: GetListingsReportCompletedEventArgs.

I am trying to deploy this on Android and iOS.(I am not worried about it working in windows phone or not)

How Can I Debug a Release Build In Visual Studio

$
0
0

I am trying to get "in app billing" working in my Android app. The only way you can test "in app billing" with your real products is to use a real device, Release mode and signed APK. I have tried "Enable Debugging" in Release mode, but no luck. The app starts but the debugger does not attach. And it does not seem like you can attach an already running process. Any ideas how to get this to work?


ListView Images from byte[] array

$
0
0

Hi --

I've had a look at this post https://forums.xamarin.com/discussion/19853/load-image-form-byte-array - as well as a few others - but my images aren't showing up in my list. I am getting 2 items in the list as expected as I have 2 photos to display. The name binding works - it will show up if I bind a label.

Xaml:

<ContentPage.Resources>
        <ResourceDictionary>
            <local:ByteArrayToImageSourceConverter x:Key="ByteArrayToImage" />
        </ResourceDictionary>
    </ContentPage.Resources>

<ScrollView>
    <ListView ItemsSource="{Binding Pictures}" ItemTapped="ItemTapped" IsPullToRefreshEnabled="true" RefreshCommand="{Binding   RefreshPicturesCommand}" IsRefreshing="{Binding IsBusy, Mode=OneWay}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Image Source="{Binding ImageBytes, Converter={StaticResource ByteArrayToImage}}"></Image>
                    <!--<Label Text="{Binding Name}" />-->
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ScrollView>

I have a model class Picture

public class Picture
    {
        public string Name { get; set; }
        public byte[] ImageBytes { get; set; }
    }

I am using the converter suggested in the linked post:

public class ByteArrayToImageSourceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ImageSource retSource = null;
            if (value != null)
            {
                byte[] imageAsBytes = (byte[])value;
                var stream = new MemoryStream(imageAsBytes);
                retSource = ImageSource.FromStream(() => stream);
            }
            return retSource;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

The converter is getting hit when the page loads and the value is a byte[], but the image does not show up.

As I am new at Xamarin, maybe there is a better way to do this. My goal is to have users take pictures, store them in the file system, and show them in a list. The user can then select an image which will then navigate to another page to add a tag if desired.

Really appreciate any assistance on this. I'm at wits end.

Chris

Xamarin.Forms 2.3.4.192-pre2

$
0
0

We've pushed Xamarin.Forms 2.3.4.192-pre2 to nuget. To install the pre-release, check the pre-release option in your nuget manager and install this version.

If you’ve got a bug to report, drop us a quick report here so we can troubleshoot in detail.

2.3.4.192-pre2

For all the details, please read the release post here.

2.3.4.184-pre1

This release builds upon 2.3.4.184-pre1. Revisit that thread discussion here.

Language support for Hindi, Thai and Korean. I can't display texts in these languages.

$
0
0

Hello

I am having problems to display texts in these languages. For instance, if I set the Text property like this, when I run the app the labels don't display the text:

this.hindiLabel.Text = languages[0]; // the value is "हिंदी"
this.thaiLabel.Text = languages[1]; // the value is "ไทย"
this.koreanLabel.Text = languages[2]; // the value is "한국어"

I checked it, Text properties are properly set with these strings.

Why use the same namespace in projects Xamarin.Forms?

$
0
0

Hi,
I am creating an application in xamarin.forms but when I seek information many from demos on your project use the same namespace, this is a standard for building applications xamarin.forms, or only that at the end of copilar the project will create a single dll file.

Navigating between two WebViews

$
0
0

Good afternoon, everyone,

We are currently working on an app that has our responsive site within a webview. In some cases, there are links that redirect to outside of our site's domain. We don't want to have these new links open in the browsers on the user's device, but open a separate instance of a webview, that we can then provide a navigation option back to the main webview which contains our site. We have put in on the Navigating event args that if the url is not in our domain, that's when it should push up to a second content page with a webview that goes to the url

I've been able to get the navigation options working to push/pop between webviews, and using Navigation.PushAsync() to the new page which has a webview does load the new webview. But, when using Navigation.PopAsync() to go back to the preview page, the webview that loads is the same webview from the new page that was pushed.

Does anyone have any tips on how to keep the two webviews separate, so that when we navigate back to the original webview, it's state is retained?

Thanks!

Viewing all 91519 articles
Browse latest View live


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