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

New VS update cause UWP crash with Maps

$
0
0

Xamarin forms new apps with maps crash with the latest VS and Libraries. this code below was working before but now it does't

Internet is ok, Internet Capability is on. (No need to location capability the previous project works without it as I am just showing map)

<?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:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
             x:Class="MapTest.MainPage">

    <ScrollView>
        <StackLayout>
            <maps:Map x:Name="Map" />
        </StackLayout>
    </ScrollView>

</ContentPage>

namespace MapTest.UWP
{
    public sealed partial class MainPage
   {
     public MainPage()
    {
         this.InitializeComponent();

         LoadApplication(new MapTest.App());

         Xamarin.FormsMaps.Init("[key works with old projects]");
    }
  }
}

I already have a Aspx Page and I would like to insert in Xamarin project and open it

$
0
0

How to open a Aspx Page in a WebView control in Xamarin ? See 2 examples that works... But with Aspx not works...

        WebView webView = new WebView
            {
                Source = new UrlWebViewSource { Url = "file:///android_asset/MyTestPage.html", },
                VerticalOptions = LayoutOptions.FillAndExpand
            };


    //WebView webView = new WebView
            //{
                //Source = new UrlWebViewSource { Url = "file:///android_asset/Page.aspx", },
                //VerticalOptions = LayoutOptions.FillAndExpand
            //};

            //Build the page.
            this.Content = new StackLayout { Children = { webView } };

Linphone + Xamarin.Forms PCL

$
0
0

Hi,

I'm looking for some advice. I am currently working on a project where we decided to investigate if Linphone is the correct path for us to go. Since we found out that there is a SDK available and documentation states that it should be able to run with a PCL project.

So I have couple of thoughts I wouldn't mind having some input on, but I'll start to explain first what I have done. According to Linphone wiki/documentation if one is using a PCL project it is not possible to have the C# wrapper in the PCL. But rather have C# wrapper in the iOS and Android project. So my idea to implement this has been as following :

  1. I created a dependencyservice which I call from the PCL to interact with the C# wrapper in the Android and iOS project, is this a good approach or should I rethink my strategy?
  2. The approach stated above does kinda work, I do actully manage to connect but when I've done so it crashes when calling a method in the C#wrapper. It crasches with a "NotImplementedException" in the C# wrapper which makes me wonder if there is a problem with the C# wrapper or maybe even the SDK itself?
  3. In the iOS project I've included the Linphone SDK as a framework and added it as native references as stated in the documentation, but here I keep getting a DLL not found error which confuses me a bit.

If anyone has any input or ideas I am more than happy to hear them.

My Virtual CarouselPage with wrap around even on Android

$
0
0

Hi,

I just wrote this little CaraouselPage class. It uses only three pages. After every PageChange the

        protected virtual void UpdatePages(ContentPage leftPage, ContentPage rightPage) { }

Method is called with references to the two at this time invisible Pages. There you can update the data on this Pages.
By setting the Properties

        public bool NoSwipeLeft { get; set; } = false;
        public bool NoSwipeRight { get; set; } = false;

You can limit swiping directions.

It does not work correct on UWP due to bugs in CarouselView in UWP.
If someone could test it on IOs, it would be great as I don't have a Mac.

Have fun, I hope someone might find it useful:

   public class VirtualCarouselPage : CarouselPage
    {
        protected ContentPage LeftPage;
        protected ContentPage LastCurrentPage;
        protected ContentPage RightPage;
        private bool startUp;


        public bool NoSwipeLeft { get; set; } = false;
        public bool NoSwipeRight { get; set; } = false;



        //Has to be called before Page is displayed e.g. assigned to MainPage
        // At initial Display activePage will be displayed.
        protected virtual void InitPages(ContentPage leftPage, ContentPage activePage, ContentPage rightPage)
        {
            startUp = true; //necessary to prevent OnCurrentPageChangeEvents having effects

            Children.Add(leftPage);
            Children.Add(activePage);
            Children.Add(rightPage);

            CurrentPage = activePage;
            RightPage = rightPage;
            LeftPage = leftPage;
            LastCurrentPage = CurrentPage;

            startUp = false;

        }


        // Will be calles after each Pagechange, so that you can update the 
        // data on the two adjoing now invisible pages
        protected virtual void UpdatePages(ContentPage leftPage, ContentPage rightPage) { }



        protected override void OnCurrentPageChanged()
        {

            System.Diagnostics.Debug.WriteLine("\n...............Swipe..........\n");

            if ((!startUp) && (CurrentPage != LastCurrentPage))
            {
                if (CurrentPage == RightPage) //swipe left
                {
                    System.Diagnostics.Debug.WriteLine("\n...............Swipe Left..........\n");

                    if (!NoSwipeLeft)
                    {
                        Children.RemoveAt(0);
                        Children.Add(LeftPage);

                        RightPage = LeftPage;
                        LeftPage = LastCurrentPage;
                        LastCurrentPage = CurrentPage;
                    }
                    else
                    {
                        CurrentPage = LastCurrentPage;
                    }

                }
                else //swipe right
                {
                    if (!NoSwipeRight)
                    {
                        Children.RemoveAt(2);
                        Children.Insert(0, RightPage);

                        LeftPage = RightPage;
                        RightPage = LastCurrentPage;
                        LastCurrentPage = CurrentPage;
                    }
                    else
                    {
                        CurrentPage = LastCurrentPage;
                    }
                }
                UpdatePages(LeftPage,RightPage);
            }
            base.OnCurrentPageChanged();
        }
    }

Intellisense not working in one solution

$
0
0

Hi,

I'm having an issue with my Xamarin Forms solution.
Basically, the intellisense doesn't work for most files in the project.
The only way I can see errors is to build the project, have it fail, and then switch the error list in Visual Studio to 'Build Only'

If I copy & paste any code segment into a new Xamarin solution, then intellisense works as normal.
Does anyone have any advice? This is quite an impediment to development..

Thanks.

App Crashed due to "Value cannot be null. Parameter name: source" Error

$
0
0

Value cannot be null. Parameter name: source exception i have updated Xamarin Forms to the latest Version

Editor and cursor colour

$
0
0

Hi guys,
in my one previous post I asked and wrote the solution to change a cursor color in an Entry. I tried to use the same code for an Editor but I can't see the cursor.

Do you have any ideas? Thank you in advance

unhandled exception

$
0
0

Hi,

i'm trying to run my app deployed on my phone, the part of code that sets off the error is a method that allows me to hide or show buttons from my expendable listview.

Here's


the code and the errors.


Xamarin.forms display PDF in webview not working

$
0
0

Hi There,

I download a pdf stream from my server. In my app I save the bytearray to a the local folder as pdf. But when I open it in the webview, it just shows a white page.

I followed this example: https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf.

Here is my xaml:

<local:CustomWebView x:Name="customView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />

Here is my code of the custom view:

 public class CustomWebView : WebView
    {        
        public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
       returnType: typeof(string),
       declaringType: typeof(CustomWebView),
       defaultValue: default(string));

        public string Uri
            {
                get { return (string)GetValue(UriProperty); }
                set { SetValue(UriProperty, value); }
            }
    }

This is my method to retrieve the pdf byte array and store it locally:

 private async void ReadPDF()
        {
            var response = CommonLibrary.Helpers.HTTPClientHelper.DownloadPDF(AccountBL.AccessToken, APISettings.APIURI("api/booking/pdf"));
            var streamContent = response.Content as System.Net.Http.StreamContent;
            var bytes = CommonLibrary.Helpers.FileHelper.ReadBytes(await streamContent.ReadAsStreamAsync());
            var dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var fileName = "test.pdf";
            CommonLibrary.Helpers.FileHelper.WriteFileFromByteArray(bytes, dir, fileName);

           customView.Uri = System.IO.Path.Combine(dir, fileName);            
        }

Am I missing something?

How to create a custom button in Xamarin Form

$
0
0

Hi every body!
As the title, how to create custom button
Thank you!

Numerous errors in values.xml after upgrading Xamarin.Forms

$
0
0

I recently upgraded all of my nuget packages for a project, and since then I can no longer build. I figured out most of the issues, but the last one is the one stopping me from building, which means I can't get a deliverable to my director.

Through searching on Google, this error is usually related to target framework mismatches, however I've set ALL frameworks (including the minimum, just to rule that out) to the same level: Android 8.0

To be clear, all of my nuget packages are on the latest version, so it's not that I need to upgrade any of them. I'll attach my packages.config just for reference. (Will have to rename, apparently .config files are not allowed to be uploaded?)



Just for reference

Updates:
- So, I just noticed in the obj\Debug\build.props file: AndroidSdkBuildToolsVersion=23.0.0
I don't even have 23 installed... only 26. 23.0.0 is marked as obsolete in SDK manager.

I tried adding
<AndroidSdkBuildToolsVersion>26.0.3</AndroidSdkBuildToolsVersion>
to my .csproj file, which did tell the build.prop to compile using the correct version, but I'm still getting the error.

Can't get location

$
0
0

Hi,

I'm using Xamarin.Mobile to get the curernt location for the device. I have read the it does not work in the simulator.
Now I have testet it on a device (IOS 9.1)

But with no luck.
The GetPositionAsync never returns.

`public async Task GetCurrentLocation()
{
var locator = new Geolocator { DesiredAccuracy = 50 };
var cancelSource = new CancellationTokenSource();
var location = GeoLocation.Undefined;

        await locator.GetPositionAsync(1000, cancelSource.Token).ContinueWith(
            t => location = t.IsCompleted 
                ? new GeoLocation(t.Result.Latitude, t.Result.Longitude) 
                : GeoLocation.Undefined, 
            cancelSource.Token);

        return location;
    }`

Anyone that knows what to do?

Br Morten

Weird behaviour with advanced Binding

$
0
0

Hi

Hi have a singleton clase who has this properties:

private string mensaje;
    private bool isDownloading;
    private string progress;

    #region BINDING PROPERTIES
    public string Mensaje
    {
        get
        {
            return mensaje;
        }
        set
        {
            mensaje = value;
            RaisePropertyChanged(() => Mensaje);
        }
    }

    public bool IsDownloading
    {
        get
        {
            return isDownloading;
        }
        set
        {
            isDownloading = value;
            RaisePropertyChanged(() => IsDownloading);
        }
    }

    public string ProgressValue
    {
        get
        {
            return progress;
        }
        set
        {
            progress = value;
            RaisePropertyChanged(() => ProgressValue);
        }
    }

    #endregion

I have a view who uses this singleton in a way like this

<Grid
            Grid.Row="4"
            Grid.ColumnSpan="2"
            Opacity="{Binding Opacity}"
            IsEnabled="{Binding IsOnline}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Label Grid.Row="0"
                   HorizontalOptions="StartAndExpand"
                   VerticalOptions="Center"
                   FontSize="Small"
                   Text="{Binding Mensaje, Source={x:Static helpers:DescargaOffline.Current}}"
                   IsVisible="{Binding ISDownloading, Source={x:Static helpers:DescargaOffline.Current}}"/>

    <!-- PROGRESS-->
            <!--<ProgressBar Grid.Row="1" Scale="5"
                         IsVisible="True"
                         IsEnabled="True"
                         Progress="{Binding ProgressValue, Source={x:Static helpers:DescargaOffline.Current}}"/>-->
            <!-- INDICATOR -->
            <ActivityIndicator
                Grid.Row="1"    
                HeightRequest="100"
                IsRunning="{Binding ISDownloading, Source={x:Static helpers:DescargaOffline.Current}}"
                IsVisible="{Binding ISDownloading, Source={x:Static helpers:DescargaOffline.Current}}"
                VerticalOptions="Center"
                HorizontalOptions="EndAndExpand"/>

            <Button        
                Grid.Row="2"
                HorizontalOptions="FillAndExpand"
                Command="{Binding DoDownloadCommand, Source={x:Static helpers:DescargaOffline.Current}}"                    
                Text="DESCARGAR OFFLINE"                    
                Style="{StaticResource DefaultActionButton}"/>
            <StackLayout  Grid.Row="3"
                          Margin="0,0,0,20"
                          Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
                <Label Text="ÚLTIMA DESCARGA " FontSize="Small"/>
                <Label Text="XX/XX/XXXX" FontSize="Small"/>
            </StackLayout>      
        </Grid>

In the singleton I start a big download process who moves from diferent functions. At the start of the launch I do IsDownloading = true and in the middle of the process I change the Mensaje value and the ProgressValue.

All works ok, except the progress bar or the activity indicator.
In the case of the progress bar the bar is showed but never changes. I have a function who changes the ProgressValue like this:

     private void ProgressCalculator(int current, int max)
    {
        double val = (double)(current + 1) / (double)max;
        ProgressValue = val.ToString().Replace('.', ',');
    }

In the case of the activity indicator it never becomes visible.

Xamarin Forms Editor - Completed raised when the control gets unfocused

$
0
0

Hi,

I'm currently working on the last part of my studying project and I have to implement a chat functionality. I then began by realizing it from a new project (faster for testing to me). However, I am facing something, I don't know if it's a bug but there is the situation:

First, the problem comes from the input, there are two controls I will take as example:

  • Entry
  • Editor

I would like to use Editor for its multiline capability, it makes it more readable to me (Maybe it's possible from a simple Entry, but that's not the point I wanna focus on).

I can type my text, everything is good, but it's when I want to send this text that my problem is. In fact, it doesn't seem possible to have a submit button in the keyboard (I couldn't make it), so I created a button (which is gray, at the right of the input).

When I click that Button, you and me agree that we 'unfocus' the Editor, so Unfocused is raised and the method attached public void OnInputUnfocused(object sender, FocusEventArgs fe) {} is called.

So my question is: Why Completed is called too?

I put the project on github: https://github.com/Emixam23/ChatAppExample


If you take a look at the README or just by scrolling down, you will see some information about it and how to try the two different behaviors between Entry and Editor

Thanks for any help!

What are the cases that a BindableProperty's propertyChanged is called multiple times?

$
0
0

I have a custom control that has an ItemsSource property, that I set in XAML like so:

<Controls:RadioButtonsGroup Grid.Column="1" ItemsSource="{Binding lstGender}" Orientation="Horizontal" SelectedItem="{Binding SelectedGender}" HorizontalOptions="Fill"/>

backing property:

public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable<object>), typeof(RadioButtonsGroup), propertyChanged: OnItemsSourceChanged);

the problem is that the OnItemsSourceChanged method is called multiple times when I go back from the page and enter it again.


Place an Absolute layout on Stack layout

$
0
0

Hi all. I need your help.
How to implement the following:
1. I have stack layout with content: label, image and etc...
2. I want to be able to move Label across the screen.

AbsoluteLayout must be placed over StackLayout. How to implement something similar?

how to call platform specific method from a shared code class

$
0
0

I wonder if it is just not the designed way to call platform specific methods from a shared code class even the class is implemented cross platform.
To make it specific, I have a webview object created with xaml code in a shared project. I want to clear the cache of the webview after it is used. Since the method of clearing is different for iOS and Android, I have to use platform specific methods. But when I tried to use some simple compiler condition

if __ANDROID__

        WebPg.clearCache(true);// Android-specific code

endif

The compiler reported that there is no method of clearCache. But clearCache is obviously a method of Android webview as defined here
https://developer.android.com/reference/android/webkit/WebView.html#clearCache(boolean)

I can understand that Android webview may not be the base class for Xamarin Webview class, so it is not recognized as a member method. But in my case, I don't want to move the whole webview related operations to platform specific, instead, I want to keep using the Webview class for its simplicity. Is there anyway to get access to the Android/iOS method with the cross-platform WebView class instance?

Shared library

$
0
0
Hello all

I am developing an app that will have a asp.net core 2.0 website as well as Xamarin Forms Android and iOS apps. I need to have a library or dll that can be shared across the Xamarin Forms and asp.net core 2.0 app. I am not going for cross platform with asp.net core, it will be a windows deployment. Can I use a simple .net class library or do I need something else?

Thanks in advance!

Google ad mob issue

$
0
0

Good day. Trying to add advertisement banner to my app. So I found manual - https://montemagno.com/xamarinforms-google-admob-ads-in-android/ . So I've done everything as James said, but got a problem.
The issue started when I update custom xmlns name space:
xmlns:controls="clr-namespace:AppTest.Controls;assembly=AppTest"
I've got error: Failed to resolve assembly: 'AppTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
Why can it be?
Though when I tried to compile without xaml extensions, I've got java.OutOfMemoryError.
So what can wrong with my app or what is wrong with Google Play Ads package?
Some methods are deprecated, may be this package is not good to use?

Should we really Unsubscribe from all events onDisappearing?

$
0
0

Which events should we unsubscribe in order to avoid memory leaks. For example i have listview in my xaml? in my case I am using syncfusion listivew, it has ItemHolding event, Should I unsubscribe in OnDisappearing method? if yes, that means that it makes no sense to define in xaml, as it will be created through constructor, so it is better to use it in OnAppearing method? Can somebody please confirm the best way to work with such events?

  <sfListView:SfListView x:Name="list"    ItemHolding="listSets_ItemHolding"        
Viewing all 58056 articles
Browse latest View live