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

is there a Tabbed view in Xamarin.forms?

$
0
0

Hello,
any idea how to make a Tabbed view in xamarin.forms,
i only found Tabbed page which is not possible to put it inside a content page!

choosing Xamarin.forms is bad choice? should i've used each platforme beside with xamarin.android and xamarin.ios!

Thanks in advance


net5.0 solution with Xamarin.Forms (iOS, Android) project

$
0
0

Does the current preview of net5.0 (5.0.100-preview.8.20417.9) with Visual Studio 2019 preview (Version 16.8.0 Preview 2.1) supports a solution that contains a C# net5.0 library and a Xamarin.Forms project (iOS, android) that is using this net5.0 library project as reference?

screenshot of mentioned solution

To me the preview 8 - release info is a bit unclear in this direction.

...We expect to deliver the rest of the vision, largely focused on Xamarin (iOS and Android), with .NET 6.0. ...

Does this mean, the mentioned use case of my question will be supported with net6.0?

Selecting Picker Item from Objects

$
0
0

Hi All,

How do I go about changing the selected item of a Picker when I have bound an object to it, rather than a list of strings?

I am still trying to wrap my head around data binding and what not, but I am having some issues with the Picker class objects. Here is my code:

List<Word> parentWordList = WordList.GetAllWords();

parentWordPicker = new Picker { HorizontalOptions = LayoutOptions.FillAndExpand };
parentWordPicker.SetBinding(Picker.ItemsSourceProperty, "Words");
parentWordPicker.SetBinding(Picker.SelectedItemProperty, "SelectedWord");
parentWordPicker.ItemDisplayBinding = new Binding("word");

var parentIndex = parentWordList.Find(x => x.wordID == parentWordID).wordID;

parentWordPicker.ItemsSource = parentWordList;
parentWordPicker.SelectedItem = ????????????????

My original attempt was:

parentWordPicker.SelectedItem =parentWordList.Find(x => x.wordID == parentWordID);

But that did not work.

God what I wouldn't give for a simple bloody dropdownlist.

The primary issue I am running into (and why I am not just using strings) is because there is the possibility of duplicate words in the list, with their ID being the unique key, so preferably I should be able to do something like: parentWordID = parentWordPicker.SelectedItem.wordID; or what ever the equivalent is. I'm still not sure how the heck I am going to do that, but I will cross that bridge when I come to it.

[VS] Copy existing app, but with different SQlite local DB data

$
0
0

I created beta app for Android with local SQlite DB data.
I would like to create copy of this app for production, but with a different SQlite DB data. Same models, but different data source. I don't want to share DB between beta and production-ready app.

How to achieve this?

Video player in Xamarin forms too slow to start buffering/playing

$
0
0

I was experimenting with some nuget package video players in Forms, and I tried

  1. the new experimental MediaElement video player
  2. the Nuget package Xam.Forms.VideoPlayer which seems to be based on the sample video player at https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/customrenderers-videoplayerdemos/
  3. Nuget package @ https://github.com/adamfisher/Xamarin.Forms.VideoPlayer that is no longer maintained.

However, they all seemed to take a long time to start buffering, and then a long time before they finally started playing.

I compared the three and the fastest to start playing seemed to be Xam.Forms.VideoPlayer (marginally faster than other two).
Finally, I timed just this one, loading a video from Amazon s3. It took about 10 seconds before the video element sized itself to the correct aspect ratio and started buffering. Then another 10 seconds before it started actually playing, for a total of 20 seconds.

By way of comparison, when I opened the s3 link directly in my Edge web browser, it took only 10 seconds to start playing.

I was wondering if others are also experiencing the same performance? Is this normal?

Thanks for reading/commenting.

By the way, this is my code:

                    <video:VideoPlayer
                        x:Name="videoPlayer"
                        AutoPlay="False"
                        BackgroundColor="White"
                        HeightRequest="300"
                        IsBuffering="{Binding IsVideoBuffering, Mode=OneWayToSource}"
                        IsVisible="{Binding IsVideoVisible}"
                        Source="{Binding VideoSource}" />

Page "OnAppearing" event from other page begin called when another page appears

$
0
0

So I have a weird behavior happening on my app (Only tested on Android).

I'm using Shell, and when the app loads, the first page of my flyout appears, which is a list of items (ItemsListPage).

When I click in a toolbar item from that page (to add a new item), I execute the given code:

Shell.Current.Navigation.PushAsync(new ItemPage(), true);

Now, in the new ItemPage I have a button connected to a command that executes a QRCode reader (from ZXing.Net.Mobile NuGet package).

If I go back (cancel the QRCode reader, by pressing the Android back key), the event PageAppearing from the ItemsListPage gets called.

Does anyone know why that happens? When I cancel the QrCodeReader, my ItemPage is the one that appears, not the ItemsListPage, so why does that event gets fired?

Thanks in advance!

CSS linear gradient is wrong

$
0
0

I use Xamarin.Forms with CSSS and in my CSS I have a linear gradient like so:
^contentpage {
background: linear-gradient(180deg, #54816E 4.3%, #E5E9F7 100%);
}

This was originally exported from Figma, and both in Figma and other CSS online editors, the gradient is starting from the bottom and to the top.

But in Xamarin forms, it starts from left to right.

  1. Why it's not the same?
  2. Why CSS is not shown in the xamarin forms previewer?

Send Push Notifications to both android and ios using Azure hosted Web Api

$
0
0

Hi,
I am new to Web Api's,

I have the following WebApi hosted in Azure. I also have all the framework to send push notifications to both android and ios devices. I have a push notification hub in azure and a Xamarin forms app created. I can send notifications individually to each device (ios + android) from the Push tab under the Notification Hub i have created on the Azure Portal and it works perfectly.

Questions are:

How can I use this Web Api locally to send notifications at once to both devices?
Or Can I use Postman to connect to this WebApi and do this, and if yes how?

[RoutePrefix("sanotifications")]
    public class SANotifController : ApiController
    {


        [HttpPost]
        [Route("")]
        public async Task<IHttpActionResult> SendNotificationAsync ([FromBody] string message)
        {
            //Get the settings for the server project
            HttpConfiguration config = this.Configuration;

            try
            {
                await InternalSendNotificationAsync(message, null);
            }
            catch (Exception ex)
            {
                //write the failure result to the logs
                config.Services.GetTraceWriter().Error(ex.Message, null, "Push.SendAsync Error");
                return BadRequest(ex.Message);
            }

            return Ok();
        }

        [HttpPost]
        [Route("{installationid}")]
        public async Task<IHttpActionResult> SendNotificationAsync(string installationId, [FromBody] string message)
        {
            //get the settings for the server project
            HttpConfiguration config = this.Configuration;

            try
            {
                await SendNotificationAsync(message, installationId);
            }
            catch (Exception ex)
            {
                //write the failure to the logs
                config.Services.GetTraceWriter().Error(ex.Message, null, "Push.SendAsync Error");
                return BadRequest(ex.Message);
            }

            return Ok();
        }



        async Task<NotificationOutcome> InternalSendNotificationAsync (string message, string installationId)
        {
            //Get the settings for the server project
            HttpConfiguration config = this.Configuration;

            //use code below if web api is already published to Azure to get existing setup
            //does not work locally
            var settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            /*
            //Get the Notification Hubs credentials for the Mobile App
            string notificationHubName = settings.NotificationHubName;
            string notificationHubConnection = settings.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString;
            */

            //the name of the Notification Hub from the overview page.
            // works locally
            string notificationHubName = "sa1hub";

            //use "DefaultFullSharedAccessSignature" from the portal's Access Policies
            string notificationHubConnection = "Endpoint=sb://sahub.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=71S2@QEWF#@$";


            // create a new notification hub client
            var hub = NotificationHubClient.CreateClientFromConnectionString(
                notificationHubConnection,
                notificationHubName,
                // Don't use this in RELEASE builds. The number of devices is limited.
                // If TRUE, the send method will return the devices a message was 
                // delivered to.
                enableTestSend: true);

            // use a template compatible with both devices
            // send the message so that all template registrations that contain "messageParam"
            // will receive the notification. This includes APNS, GCM, WNS and MPNS template registrations.
            var templateParams = new Dictionary<string, string>
            {
                ["messageParam"] = message
            };

            // send the push notification and log the results

            NotificationOutcome result = null; 
            if (string.IsNullOrWhiteSpace(installationId))
            {
                result = await hub.SendTemplateNotificationAsync(templateParams).ConfigureAwait(false);
            }
            else
            {
                result = await hub.SendTemplateNotificationAsync(templateParams, "$InstallationId:{" + installationId + "}").ConfigureAwait(false);
            }

            // Write the success result to the logs.
            config.Services.GetTraceWriter().Info(result.State.ToString());
            return result;
        }


    }
}

Licensing an App without a Store

$
0
0

I do not distribute my apps via a store but simply by distributing APK files, because my apps are always only used within one company. But I would like to do some kind of licensing and keep an overview of how many versions of the app are in use. The problem is that the customer could theoretically run an app on different devices, which would be allowed by me if a device should break down. If I would bind the license directly to the device it would be relatively easy, but I need a solution that prevents the same app from running on two devices in parallel. I do not want to reinvent the wheel so I hope to find a solution here without using App-Center. I am thinking about an own Webservice that keeps track of the Logins...

Picker behaviour on Android

$
0
0

Hi,

I'm not sure if this is by design, or a bug - but in Android, a Picker control seems to allow the user to type in any old text, i.e. not limit the selection to just the ItemsSource collection.

Click on a Picker.
It's list of items will be displayed.
Click Cancel to dismiss the list.
Notice the picker still has focus.
Type on the physical keyboard of the device.
The text typed in will appear in the Picker! The SelectedIndex won't fire etc so the Picker actually doesn't have any selected item, but that text appearing will stay there even if you move focus to another control - obviously giving the appearance that something is selected!

Text of Radio Buttons not showing anymore

$
0
0

After Updating from 4.7.0 968 to 4.8.0 1238 I was facing Problem with my Radio Buttons. I don´t know from which Version it startet but I downloaded the official Demo for Radio Buttons from the Xamarin Page and I have the same Problem.

iOS "Files" app, Android ExternalStorageDirectory and saving files

$
0
0

Hello,

Trying to rephrase a question I've asked before.

I'd like to save a generated .pdf file into a common folder on a device so that a user can find those files from say email app for an attachment or just view the file external to my app.

On my iOS device, I can open Files app and browser to various folders. I noticed some apps have their own folders under "On my phone" and I can manually create a folder there too.

I'd like my app to create it's own public folder on the device and save pdf files into that. The user can then view those files by simply navigating to that folder using the Files app without needing to use my app.

Found these two links - files in iOS
and this BlogPost for Android

Can anyone else advise?
As there a plugin or sample code that'll help?

I'm expecting to write a dependency service for this on each platform.

Thanks

swipeview inside a tabbedpage bug

$
0
0

Why is this happening? How can I solve it?

https://i.gyazo.com/d6c51e004b4b62f3a9ccfcf37c186c3b.mp4

            <RefreshView IsRefreshing="{Binding IsBusy, Mode=TwoWay}" 
                         Command="{Binding CargarPedidosPendientesCommand}" 
                         Grid.ColumnSpan="4">
                <ListView x:Name="listViewPedidos" 
                          HasUnevenRows="True" 
                          ItemsSource="{Binding Pedidos}" 
                          ItemTapped="listViewPedidos_ItemTapped">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <SwipeView>
                                    <SwipeView.LeftItems>
                                        <SwipeItems Mode="Execute">
                                            <SwipeItem Text="Borrar" 
                                                       IconImageSource="delete.png"
                                                       BackgroundColor="Red"  
                                                       Command="{Binding Source={x:Reference listViewPedidos}, Path=BindingContext.BorrarPedidoCommand}" 
                                                       CommandParameter="{Binding .}"/>
                                        </SwipeItems>
                                    </SwipeView.LeftItems>
                                    <SwipeView.Content>
                                        <Grid>
                                            <Label>
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="{Binding Id, StringFormat='Pedido Nº: {0} —'}"/>
                                                        <Span Text="{Binding Fecha, StringFormat=' Fecha: {0:dd-MM-yyyy}'}"/>
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>

                                            <Label Grid.Row="1">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="{Binding ImpTotal, StringFormat='Total: ${0:n} ('}"/>
                                                        <Span Text="{Binding Renglones, StringFormat='Rn:{0:n0} /'}"/>
                                                        <Span Text="{Binding Unidades, StringFormat=' Un: {0:n0})'}"/>
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>

                                            <Label Text="{Binding ApellidoCliente, StringFormat='Cliente: {0}'}" Grid.Row="2"/>
                                        </Grid>
                                    </SwipeView.Content>
                                </SwipeView>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </RefreshView>

use binding correctly

$
0
0

Hello,
In part of my code, I successively call two routes of an API ("connection login password" then "user information retrieval"). I want to display the answers for each of the two routes on the same page on the screen. The second route uses the response from the first route as an argument.

My code below works but it is not correct: The call to the second route clears the responses displayed in the labels of the first route and if a property has the same name on both instances, the display will be incorrect...

page_gestion_webservice.xaml

    <StackLayout Margin="20,35,20,20">
            <StackLayout>
                <Entry x:Name="login_login_st"
                       Text="test@test.com"
                       Placeholder="email" />
                <Entry x:Name="login_password_st"
                       Text="test"
                       Placeholder="mot de passe" />
                <Button Text="to connect"
                        Clicked="call_api_login" />
                <Label>
                    <Label.FormattedText><FormattedString>
                        <Span Text="success : " /><Span Text="{Binding login_user_success_bo}" />
                        </FormattedString></Label.FormattedText>
                </Label>                
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="error : " /><Span Text="{Binding login_user_error_st}" />
                        </FormattedString></Label.FormattedText>
                </Label>
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="token : " /><Span Text="{Binding login_user_token_st}" />
                        </FormattedString></Label.FormattedText>
                </Label>
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="userid : " /><Span Text="{Binding login_user_userid_i}" />
                        </FormattedString></Label.FormattedText>
                </Label>                
            </StackLayout>
            <StackLayout>
                <Button Text="recup user info"
                        Clicked="call_api_userid" />
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="success : " /><Span Text="{Binding userid_success_bo}" />
                        </FormattedString></Label.FormattedText>
                </Label>
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="error : " /><Span Text="{Binding userid_error_st}" />
                        </FormattedString></Label.FormattedText>
                </Label>
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="prenom : " /><Span Text="{Binding userid_firstname_st}" />
                        </FormattedString></Label.FormattedText>
                </Label>
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="nom : " /><Span Text="{Binding userid_name_st}" />
                        </FormattedString></Label.FormattedText>
                </Label>
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="genre : " /><Span Text="{Binding userid_genre_i}" />
                        </FormattedString></Label.FormattedText>
                </Label>
            </StackLayout>
        </StackLayout>

page_gestion_webservice.xaml.cs

    public partial class page_gestion_webservice : ContentPage
    {
        Response_login_user_cl response_login_user_obj;
        Response_userid_cl response_userid_obj;
        public page_gestion_webservice()
        {
            InitializeComponent();
        }

        async void call_api_login(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(login_login_st.Text) || string.IsNullOrWhiteSpace(login_login_st.Text))
                await DisplayAlert("Validation", "Please enter your email.", "OK");
            else if (string.IsNullOrEmpty(login_password_st.Text) || string.IsNullOrWhiteSpace(login_password_st.Text))
                await DisplayAlert("Validation", "Please enter your password.", "OK");
            else
            {
                Login_param_body_cl login_param_body_obj = new Login_param_body_cl(login_login_st.Text, login_password_st.Text);
                Request_api_cl request_api_login_obj = new Request_api_cl("login", Api_lapi_cl.tokengroupe_st);
                response_login_user_obj = await request_api_login_obj.request_post_login_async(Api_lapi_cl.url_base_st, Api_lapi_cl.post_login_st, login_param_body_obj);
                BindingContext = response_login_user_obj;                
            }
        }

        async void call_api_userid(object sender, EventArgs e)
        {
            if ((!string.IsNullOrEmpty(response_login_user_obj.login_user_token_st)) && (response_login_user_obj.login_user_userid_i != 0))
            {
                Request_api_cl request_api_userid_obj = new Request_api_cl("userid", response_login_user_obj.login_user_token_st, response_login_user_obj.login_user_userid_i);
                response_userid_obj = await request_api_userid_obj.request_get_userid_async(Api_lapi_cl.url_base_st, Api_lapi_cl.get_userid_st);
                BindingContext = response_userid_obj;               
            }
        }
    }


Api_lapi_cl.cs

    public class Reponse_login_user_cl
    {
        [JsonProperty("success")]
        public bool login_user_success_bo { get; set; }

        [JsonProperty("error")]
        public string login_user_error_st { get; set; }

        [JsonProperty("token")]
        public string login_user_token_st { get; set; }

        [JsonProperty("user_id")]
        public int login_user_userid_i { get; set; }
    }

    // réponse de la route user_id
    public class Reponse_userid_cl
    {
        [JsonProperty("success")]
        public bool userid_success_bo { get; set; }

        [JsonProperty("error")]
        public string userid_error_st { get; set; }

        [JsonProperty("prenom")]
        public string userid_prenom_st { get; set; }

        [JsonProperty("nom")]
        public string userid_nom_st { get; set; }

        [JsonProperty("genre")]
        // int? : rend le int nullable
        public int? userid_genre_i { get; set; }
    }

I am looking for a solution of this type {Binding response_login_user_obj.login_user_success_bo} and BindingContext = this; but my syntax is of course incorrect :

    <StackLayout Margin="20,35,20,20">
            <StackLayout>
[...]
                <Button Text="to connect"
                        Clicked="call_api_login" />
                <Label>
                    <Label.FormattedText><FormattedString>
                        <Span Text="success : " /><Span Text="{Binding response_login_user_obj.login_user_success_bo}" />
                        </FormattedString></Label.FormattedText>
                </Label>   
[...]             
            </StackLayout>
            <StackLayout>
                <Button Text="recup user info"
                        Clicked="call_api_userid" />
                <Label>
                    <Label.FormattedText><FormattedString>
                            <Span Text="success : " /><Span Text="{Binding response_userid_obj.userid_success_bo}" />
                        </FormattedString></Label.FormattedText>
                </Label>
[...]
            </StackLayout>
        </StackLayout>
        async void call_api_login(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(login_login_st.Text) || string.IsNullOrWhiteSpace(login_login_st.Text))
                await DisplayAlert("Validation", "Please enter your email.", "OK");
            else if (string.IsNullOrEmpty(login_password_st.Text) || string.IsNullOrWhiteSpace(login_password_st.Text))
                await DisplayAlert("Validation", "Please enter your password.", "OK");
            else
            {
                Login_param_body_cl login_param_body_obj = new Login_param_body_cl(login_login_st.Text, login_password_st.Text);
                Request_api_cl request_api_login_obj = new Request_api_cl("login", Api_lapi_cl.tokengroupe_st);
                response_login_user_obj = await request_api_login_obj.request_post_login_async(Api_lapi_cl.url_base_st, Api_lapi_cl.post_login_st, login_param_body_obj);
                BindingContext = this;                
            }
        }

        async void call_api_userid(object sender, EventArgs e)
        {
            if ((!string.IsNullOrEmpty(response_login_user_obj.login_user_token_st)) && (response_login_user_obj.login_user_userid_i != 0))
            {
                Request_api_cl request_api_userid_obj = new Request_api_cl("userid", response_login_user_obj.login_user_token_st, response_login_user_obj.login_user_userid_i);
                response_userid_obj = await request_api_userid_obj.request_get_userid_async(Api_lapi_cl.url_base_st, Api_lapi_cl.get_userid_st);
                BindingContext = this;               
            }
        }

Can you guide me? thank you so much.

RadioButtons Text displaying bug

$
0
0

Hi guys, i update my Xamarin Forms application to new version 4.8.0.1364 (latest stable) and radio buttons text property stop displaying text. This issue is only on Android devices, it's working ok on iOS

When i roll back to 4.7.0.1351 all works correctly


Developing a Location Background Service

$
0
0

Hi

I want my app to send a location every x minuttes, both when using the app, but also when the app is in the background.

I seen a few example of how to create a service which is running in the background with xamarin.android. (https://github.com/xamarin/mobile-samples/tree/master/BackgroundLocationDemo)

But what about xamarin.forms, which I'm working on? Could the same code be used with forms? Also I haven't seen the same for xamarin.ios.

Why can't I find a full example code of sending locations from a app, both foreground and background? I'm convinced a lot of developers could be interested in such functionallity.

I'm very new to xamarin, so I'm hoping you can point me in the right direction if its possible to develop such funcionallity.

Kind regards

How to set a Content Title FontFamily in xamarin.Forms XAML

$
0
0

Hello, I can't find a way of changing the fontfamily of the Content.Page Title like I did in the label:

<ContentPage
Title="Menu"
????

Is there any way of doing this?

Build configurations + multiple versions on the same device

$
0
0

Hi all,

what is the most efficient way to manage multiple builds on the same device?

By that - I mean i would want to run the following configurations:

  1. Release Xamarin App connecting to Production API
  2. Release Xamarin App connecting to Dev API
  3. Dev Xamarin App connecting to Production API
  4. Dev Xamarin App connecting to Dev API

At the moment I distinguish between Prod API and Dev API by changing the Urls in the code directly which is cumbersome..

How to set badge in toolbaritems xamarin.forms shell?

Gesture recognizers and portability

$
0
0

I have a CollectionView and am using a gesture recognizer to trap a double-tap event. I also have the CollectionView enabled for Single select. This all seems to work with the UWP version, but on Android I don't get the double tap. I can see the single selection working, but the double taps don't seem to be recognized. Any help is greatly appreciated. Thanks.

Viewing all 79144 articles
Browse latest View live


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