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

[Android] Maps not working on Google Play store

$
0
0

I am using the Xamarin.Forms.GoogleMaps plugin, but the same happens with Xamarin.Forms.Maps.

  • I created a Google API Key, and I restricted it for android, using the package name and SHA1 from the keystore that I use to publish the app to Google Play.
  • I archived the android app, signed with my keystore.
  • It saved the APK to the computer.
  • I installed that APK to the phone, and maps work just fine.

  • I manually uploaded that same APK to Google Play and created a new alpha release.

  • I deleted the app (with the working maps) from my phone.
  • I installed the app from Google Play
  • The maps are blank!

NOTE
When I go to Google Play Console and download the APK and try it on my phone, I get these results:

  • Original APK: maps work
  • Derived APK: maps are blank

I don't understand what's wrong, can anyone please advise?
Thanks


XAML Image doesn't show up

$
0
0

Hello,

I've tried so many things and I am very upset..

This is my code

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App1.PictureTest">
    <StackLayout>
        <Image Source="images/picture.jpg" />
        <Label Text="Hello" />
    </StackLayout>
</ContentPage>

As you can imagine, I created a folder "images" in my project ("App1"). I pasted a picture called "picture.png" in it and added the picture as a Resource to the project. It cannot bring it to show up.. it just doesn't work.

What I tried so far:
*Messing around with the path, like pasting the full path, using URLs, only "picture.png", only "picture", "../picture.png/" and so on
*Pasting the folder in other locations
*Using the picture as "EmbeddedResource"
*Using other pictures
*reboot pc and visual studio
*creating a new project
*... and many other things

As I'm writing this, I'm getting a new error.

namespace App1
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new PictureTest();
        }
...

InitializeComponent() is now highlighted as an error (which was never the case before). "CS0103: The name "InitializeComponent" does not exist in the current context"

Please help me. Thanks.

Edit: accidentally posted this thread twice because I thought it didnt post. Dont know how to delete this

Invalid value for slider minimum

$
0
0

Hello,

i'm trying to set a minimum value for a slider:
Slider slider = new Slider { Minimum = 30.0, Maximum = 60.0, Value = 45.0 };

This results in an exception:

System.ArgumentException: Value was an invalid value for Minimum

Parameter name: value

I can set the minimum without problems to zero or a negative value, but a value greater than zero throws the error.

Is this working as intended or a bug?

Regards,
Dirk

Generate/Display Controls Dynamically in Xamarin Forms

$
0
0

Hi Everyone,

I recently started learning Xamarin (MVVM). I am basically trying to convert a traditional Xamrin app to Xamarin Forms (MVVM). I need to remove all the code from code-behind and implement MVVM architecture. I have List objects(some types). I am populating that list using a picker. My task is generate dynamic controls(UI) based on picker selection. For example, if I select type-a in the picker, the stacklayout below the picker should have four entries and 2 switches, if type-b is selected, the stacklayout should display five other controls. In general I need the functionality that generates/displays controls dynamically depending on the type of selection made from picker. I can perform this in code-behind, I add the children to the stacklayout depending on the type selected. Now I need to move this functionality to Forms and get the same done using Xaml.

Can anyone please help me with this?

Thanks a lot in advanced!

Keyboard remaining problem

$
0
0

Hello, I encounter strange issue, Keyboard is remain even when Editor is not visible.

I create a reproduce project on Github.

What I want to achieve is Lock focus on Editor while ContentView is visible and loose focus when ContentView is not visible .
I change ContnetView.Visible by button or event.

I use Asynchronous Programming because Editor.Focus() does not take effect immediately. I guess Editor.Focus() does not work when Editor is not on screen. Therefore I wait 100 ms and retry Editor.Focus() until Editor.IsFocused is true.

    public partial class MyView : ContentView
    {
        public MyView()
        {
            InitializeComponent();
            Editor.Unfocused += OnEditorUnfocused;
        }

        void Button_Clicked(object sender, EventArgs e)
        {
            IsVisible = false;
        }

        private async void OnEditorUnfocused(object sender, FocusEventArgs e)
        {
            if (IsVisible)
            {
                await FocusEditorAsync();
            }
        }

        private async Task FocusEditorAsync()
        {
            while (!Editor.IsFocused)
            {
                Editor.Focus();
                await Task.Delay(100);
            }
        }

        private async Task UnfocusEditorAsync()
        {
            while (Editor.IsFocused)
            {
                Editor.Unfocus();
                await Task.Delay(100);
            }
        }

        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (propertyName.Equals("IsVisible") && IsVisible)
            {
                // make initial focus when visible
                FocusEditorAsync();
            }

            base.OnPropertyChanged(propertyName);
        }
    }

More details on StackOverflow

How do i make a Bindable Path Data

$
0
0

Using the lastest xamarin Shapes Path feature, my path works when i hardcode my path data. I can't seem to figure how to make that Path Data bindable. Anyone can help with that?

Observable collection help

$
0
0

Hello everyone

I have a tiny problem with my observable collection.
I am using firebase with a plugin (https://github.com/f-miyu/Plugin.CloudFirestore) and it works great, but I have two a problem

here I am saving a pet

            pet.ImageURL = imageprincipal;
            pet.id = Id.ToString();
            pet.Nombre = NombreEntry.Text;
            pet.FechaNacimiento = fechaNacimientoEntry.Text;
            pet.Categoria = CategoriasPickerList.SelectedItem.ToString();
            pet.Raza = RazaEntry.Text;
            pet.Genero = GeneroPicker.SelectedItem.ToString();
            pet.Tamaño = Tamañopicker.SelectedItem.ToString();
            pet.Peso = pesoEntry.Text;
            pet.Descripcion = DescripcionEntry.Text;
            pet.Vacunado = Vacunado;
            pet.Esterilizado = Esterilizado;
            pet.RazaPura = RazaPura;
            pet.Amistoso = Amistoso;
            pet.Microship = Microchip;
            pet.DisponibleParejas = Disponiple;
            pet.ExtraImages = new System.Collections.Generic.List<string> {
                mascota, mascota2, mascota3, mascota4
            };
            pet.Owner = auth.GetUserDisplayName();

            await CrossCloudFirestore.Current
                          .Instance
                          .GetCollection("Pets")
                          .AddDocumentAsync(pet);

            await Navigation.PopAsync(true);
        }

and when I popAsync(), I go MyMascotas page, where I have a read method that gets invoke every time that page appears, but I dont see my new pet. I have to exit the screen and go back in in order for me to see it

   private async void FabBtn_Clicked(object sender, System.EventArgs e) {

            string accion = await DisplayActionSheet(null, "Cancelar",
                  null, "Usar camara", "Elegir de la galería", null);


            switch (accion) {

                case "Usar camara":
                    mediaFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions {
                        Directory = "AppetLand Photos",
                        SaveToAlbum = true,
                        DefaultCamera = CameraDevice.Front
                    });

                    if (mediaFile == null) {
                        return;
                    }
                    img = ImageSource.FromStream(() => mediaFile.GetStream());

                    mascotaImg = await StoreImages(mediaFile.GetStream(), "Imagen principal", Path.GetExtension(mediaFile.Path));

                    Preferences.Set("Mascota Prinpipal", mascotaImg);

                    await Navigation.PushAsync(new PetInfoScreen(mascotaImg));
                    break;
                case "Elegir de la galería":
                    mediaFile = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions { });

                    if (mediaFile == null) {
                        return;
                    }
                    img = ImageSource.FromStream(() => mediaFile.GetStream());

                    mascotaImg = await StoreImages(mediaFile.GetStream(), "Imagen principal", Path.GetExtension(mediaFile.Path));

                    Preferences.Set("Mascota Prinpipal", mascotaImg);

                    await Navigation.PushAsync(new PetInfoScreen(mascotaImg));

                    break;
                default:
                    break;
            }
        }

        protected override void OnAppearing() {
            base.OnAppearing();

            myMascotasViewModel.GetData();
        }

I am using also a view model to back it up

   public ObservableCollection<Pet> Pets { get; set; }
        IAuth auth;

        public MyMascotasViewModel() {
            Pets = new ObservableCollection<Pet>();

            auth = DependencyService.Get<IAuth>();

            GetData();
        }
        public async void GetData() {

            var document = await CrossCloudFirestore.Current
                                      .Instance
                                      .GetCollection("Pets")
                                      .WhereEqualsTo("Owner", auth.GetUserDisplayName())
                                      .GetDocumentsAsync();

            var p = document.ToObjects<Pet>();

            Pets.Clear();
            foreach (var item in p) {

                Pets.Add(item);
            }

            Debug.WriteLine(Pets.Count);
        }

WebView.Cookies unable to set cookies doing login flow

$
0
0

Hi,

I am developing a fairly simple shell for making IOs and android apps with a Webview at the core which knows how to handle login and receive push notifications etc. to be used in multiple other projects.

I am having trouble with using the Cookies property added in 4.6 (PR #8169)
If i don't set the Cookies property my login flow works without issues but because i want to control what happens with my sessions OnSleep and OnResume i have set it to:
WebView.Cookies = new CookieContainer();
and then suddenly no cookies are set doing my login flow.

Anyone have similar experiences? I have only tested with android so far and i have tried setting a dummy cookie in the code which works fine and seems to be persisted through the entier login flow.

Hope someone is able to help.


Getting resource ID from IconImageSource

$
0
0

Hello everyone!

I am updating an old project and came across this line with some deprecated code:

var barItems = pages.Select(x => new BottomBarTab(Context.Resources.GetDrawable(x.Icon), x.Title));

The x.Icon has now been changed to x.IconImageSource, but the BottomBarTab needs a resource id. Is there any way I can get this?

how to access camera and microphone in webview ios xamarin form?

$
0
0

we have web application for video call which is done by webrtc. This web video call works fine in android webview, but not working in ios webview. I need to know how i can access camera and microphone in ios webview xamarin form?

Security Issue of Predictable Random Number Xamarin.Forms

$
0
0

Hi,

Have been facing security issue, in simple demo app built in Xamarin.Forms with no code written is giving Predictable Random Number.
This can be tested with multiple testing websites like immuniweb.com/mobile/ in ios app as per top 10 OWASP Guidelines

It would be great if anyone can help be from Xamarin Team

Radiobutton text is not being displayed, how to fix it?

$
0
0
      <Frame Style="{DynamicResource PrimaryFrameStyle}">

                <StackLayout>

                    <Label Text="Display Setting"
                           Style="{DynamicResource SecondaryLabeltStyle}"/>

                    <RadioButton 
                        x:Name="systemSettingRadioButton"
                        Text="Use device settings"
                        Style="{DynamicResource PrimaryRadioButtontStyle}"
                        IsChecked="True"
                        GroupName="AppTheme" 
                        CheckedChanged="AppThemeRadioButton_CheckedChanged"/>

                    <RadioButton 
                        x:Name="LightSettingRadioButton"
                        Text="Light"
                        Style="{DynamicResource PrimaryRadioButtontStyle}"
                        GroupName="AppTheme" 
                        CheckedChanged="AppThemeRadioButton_CheckedChanged"/>

                    <RadioButton 
                        x:Name="DarkSettingRadioButton"
                        Text="Dark"
                        Style="{DynamicResource PrimaryRadioButtontStyle}"
                        GroupName="AppTheme"  
                        CheckedChanged="AppThemeRadioButton_CheckedChanged"/>



                </StackLayout>                   
            </Frame>

that's my code, it was working in another app i made, but now it is not working. what's a possible fix?

IOS CollectionView FirstVisibleIndex And LastVisibleIndex Bug

$
0
0

Hello,
I am working with a collectionView and there is a confirmed bug in CollectionView FirstVisibleItem and LastVisibleItem on IOS. issue reported here https://github.com/xamarin/Xamarin.Forms/issues/9989
I am hoping that there is a workaround by implementing a CollectionView renderer for IOS.

I am attaching a sample project grabbed from the Xamarin Git as a sample to demonstrate the issue.
To see the issue. Run the attached app in Xamarin.IOS
When the app loads scroll to the the "Scrolling" Section Select Scroll by Index
Now scroll to hide item1 off the screen and look at the output window you will notice that FirstVisibleItemIndex is 0, now scroll to hide the second item note that the FirstVisibleItemIndex is still 0, now hide the second item then the FirstVisibleItemIndex updates to 1 (Which by now is hidden). Also note the lastVisibleItemIndex is off by 1.

Any help would be appreciated.

How to access MySql Database from Android in Xamarin Forms?

$
0
0

Nobody yet solve this problem i guess...

When i'm using the MySql.Data package with Xamarin.Forms, my code works on iOS and Windows, it successfully connects to the online server MySQL DB, but the same code throws a System.TypeInitializationException exception on Android at the point where I call the MySqlConnection .Open(); function.

Can anyone help ? Is there any documentation available that definitively makes it clear whether Oracle's MySql.Data nuget package is compatible with Xamarin on Android or not?

Changing the colour of the back, home and recent buttons

$
0
0

Hi everyone, I have a Xamarin forms question. Is it possible to change the colour of the bottom navigation bar (back, home, opened apps) in Xamarin forms for the android part. If so, how?

Thanks!


Entry Focus Xamarin Forms MVVM

$
0
0

I need focus a entry after of click a button.

I has think in implement a Behavior but i dont know that is the problem.

This is my code.

View.

Behavior Class.

`public class EntryFocusBehavior : Behavior
{
public bool OnFocus { get; set; }

    protected override void OnAttachedTo(Entry bindable)
    {
        base.OnAttachedTo(bindable);
        bindable.TextChanged += OnEntryTextChanged;
    }

    protected override void OnDetachingFrom(Entry bindable)
    {
        base.OnDetachingFrom(bindable);
        bindable.TextChanged -= OnEntryTextChanged;
    }



    void OnEntryTextChanged(object sender, TextChangedEventArgs e)
    {
        var entry = (Entry)sender;

        if (OnFocus)
        {
            entry.Focus();
        }
        else
        {
            entry.Unfocus();
        }
    }
}`

And viewmodel.

public bool OnFocus { get; set; }

OnFocus ="True or False"

I need use PropertyChanged in view model binding??

Binding control is two away?

Thanks by help me forum community.

Text capitalization in the XAML

$
0
0

Hello,

I have a field where the user can write postal code. I want to receive the postal code in uppercase, so I capitalize it. Does Xamarin.Forms have any method to capitalize the text directly in the XAML code? I make it in the C# for now, but I want to move it to XAML if it is possible.

Thanks in advance.

Passar dados entre paginas

$
0
0

Estou usando Shell para acessar algumas ContantPages através de um Menu... A duvida é, quando acesso uma ContantPages pela primeira vez o construtor é acionado, porem quando vou pra outra tela e volto preciso de um evento para recarregar os dados dessa tela. Como Faço isso?
...
...

















Problem with cloud firestone

$
0
0

Hello guys I have a huge problem, I am using the cloud firestore plugin and it works fine, I can do my CRUD normally, but this is my problem

I have an observable collection of pets rights? so I can add a pet into my database, but it doesn't change automatically, I have to go to Home and back in to see my pets, I tried to put my class implement the IPropertychanged in every property and my view model have this

    private ObservableCollection<Pet> _pets;
        public ObservableCollection<Pet> Pets {
            get {
                return _pets;
            }
            set {
                _pets = value;
                RaisePropertyChanged("Pets");
            }
        }

        IAuth auth;

        public MyMascotasViewModel() {
            Pets = new ObservableCollection<Pet>();

            auth = DependencyService.Get<IAuth>();

            GetData();
        }
        public async void GetData() {

            var document = await CrossCloudFirestore.Current
                                      .Instance
                                      .GetCollection("Pets")
                                      .WhereEqualsTo("Owner", auth.GetUserDisplayName())
                                      .GetDocumentsAsync();



            var p = document.ToObjects<Pet>();

            Pets.Clear();
            foreach (var item in p) {

                Pets.Add(item);
            }

            Debug.WriteLine(Pets.Count);
        }
    }

class

private string _id;
        public string Id {
            get { return _id; }
            set {
                if (_id != value) {
                    _id = value;
                    RaisePropertyChanged();
                }
            }
        }

        private string _ImageURL;
        public string ImageURL {
            get { return _ImageURL; }
            set {
                if (_ImageURL != value) {
                    _ImageURL = value;
                    RaisePropertyChanged();
                }
            }
        }

        private List<string> _ExtraImages;
        public List<string> ExtraImages {
            get { return _ExtraImages; }
            set {
                if (_ExtraImages != value) {
                    _ExtraImages = value;
                    RaisePropertyChanged();
                }
            }
        }

        private string _Nombre;
        public string Nombre {
            get { return _Nombre; }
            set {
                if (_Nombre != value) {
                    _Nombre = value;
                    RaisePropertyChanged();
                }
            }
        }

        private string _FechaNacimiento;
        public string FechaNacimiento {
            get { return _FechaNacimiento; }
            set {
                if (_FechaNacimiento != value) {
                    _FechaNacimiento = value;
                    RaisePropertyChanged();
                }
            }
        }

        private string _Categoria;
        public string Categoria {
            get { return _Categoria; }
            set {
                if (_Categoria != value) {
                    _Categoria = value;
                    RaisePropertyChanged();
                }
            }
        }

        private string _Raza;
        public string Raza {
            get { return _Raza; }
            set {
                if (_Raza != value) {
                    _Raza = value;
                    RaisePropertyChanged();
                }
            }
        }

        private string _Genero;
        public string Genero {
            get { return _Genero; }
            set {
                if (_Genero != value) {
                    _Genero = value;
                    RaisePropertyChanged();
                }
            }
        }

        private string _Tamaño;
        public string Tamaño {
            get { return _Tamaño; }
            set {
                if (_Tamaño != value) {
                    _Tamaño = value;
                    RaisePropertyChanged();
                }
            }
        }


        private string _Peso;
        public string Peso {
            get { return _Peso; }
            set {
                if (_Peso != value) {
                    _Peso = value;
                    RaisePropertyChanged();
                }
            }
        }


        private string _Descripcion;
        public string Descripcion {
            get { return _Descripcion; }
            set {
                if (_Descripcion != value) {
                    _Descripcion = value;
                    RaisePropertyChanged();
                }
            }
        }

        private bool _Vacunado;
        public bool Vacunado {
            get { return _Vacunado; }
            set {
                if (_Vacunado != value) {
                    _Vacunado = value;
                    RaisePropertyChanged();
                }
            }
        }


        private bool _Esterilizado;
        public bool Esterilizado {
            get { return _Esterilizado; }
            set {
                if (_Esterilizado != value) {
                    _Esterilizado = value;
                    RaisePropertyChanged();
                }
            }
        }

        private bool _RazaPura;
        public bool RazaPura {
            get { return _RazaPura; }
            set {
                if (_RazaPura != value) {
                    _RazaPura = value;
                    RaisePropertyChanged();
                }
            }
        }

        private bool _Amistoso;
        public bool Amistoso {
            get { return _Amistoso; }
            set {
                if (_Amistoso != value) {
                    _Amistoso = value;
                    RaisePropertyChanged();
                }
            }
        }

        private bool _Microship;
        public bool Microship {
            get { return _Microship; }
            set {
                if (_Microship != value) {
                    _Microship = value;
                    RaisePropertyChanged();
                }
            }
        }

        private bool _DisponibleParejas;
        public bool DisponibleParejas {
            get { return _DisponibleParejas; }
            set {
                if (_DisponibleParejas != value) {
                    _DisponibleParejas = value;
                    RaisePropertyChanged();
                }
            }
        }

        private bool _Adopcion;
        public bool Adopcion {
            get { return _Adopcion; }
            set {
                if (_Adopcion != value) {
                    _Adopcion = value;
                    RaisePropertyChanged();
                }
            }
        }


        private string _Owner;
        public string Owner {
            get { return _Owner; }
            set {
                if (_Owner != value) {
                    _Owner = value;
                    RaisePropertyChanged();
                }
            }
        }

UI

   <CollectionView x:Name="PetList"
                            Grid.Row="1"
                            SelectionMode="Single"
                            SelectionChanged="PetList_SelectionChanged"
                            ItemsSource="{x:Binding Pets}"
                            EmptyView="Agregue fotos de su mascota"
                            HorizontalOptions="CenterAndExpand">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout>
                            <Frame Padding="5"
                                   Margin="10"
                                   CornerRadius="5"
                                   BorderColor="Black">
                                <StackLayout>
                                    <Image Source="{x:Binding ImageURL}"
                                           WidthRequest="160"
                                           HeightRequest="160"
                                           Aspect="AspectFill" />

                                    <Label FontSize="Title" FontAttributes="Bold">
                                        <Label.FormattedText>
                                            <FormattedString>
                                                <FormattedString.Spans>
                                                    <Span Text="Mascota: " />
                                                    <Span Text="{x:Binding Nombre, Mode=TwoWay}" />
                                                </FormattedString.Spans>
                                            </FormattedString>
                                        </Label.FormattedText>
                                    </Label>

I dont know if I made a bad choise of using firestore over real time database or I am doing something wrong, @YelinZh told me to implement all the properties to Inotify, and I did and still nothing and I do not think I have to swith databases, becouse when I add a document I see that is added realtime in the database

I appreciate all the help thanks

Method Not Allowed when use SendAsync() instead of GetAsync()

$
0
0

Hi guys, is me again.

I have another interesting situation

I need to send a Get request to an API but with content in the body, but I never do that previously (only with post request).

    public async Task<string> GetIdentificaciones()
        {
            try
            {
                var direURL = ApiSIF + "cuteURL";
                var uri = new Uri(string.Format(direURL, string.Empty));

                var response = await common.SIFHttpClient().GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    var jstr = await response.Content.ReadAsStringAsync();
                    var identificaciones = JsonConvert.DeserializeObject<List<Identificacion>>(jstr);

                    return response.ReasonPhrase;

                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error en la funcion para obtener Identificaciones", e.InnerException + e.Message);
            }

            return "BAD";
        }

That's the normal code to make and Get request, work fine and return 200, very good, but when I try it this code to add content to the body in a GeT request:

...
 var request = new HttpRequestMessage
  {
       Method = HttpMethod.Get,
      RequestUri = new Uri(ApiSIF + "cuteURL"),
      Content = new StringContent("83", Encoding.UTF8, "application/json")
 };

 var response = await common.SIFHttpClient().SendAsync(request);

 if (response.IsSuccessStatusCode)
{
...

It's send me a "Method Not Allowed" error code.

Anybody knows how to make this kind of request?

BTW: I'm not the dev for the API, so I cant modify anything in the API project.

Viewing all 79144 articles
Browse latest View live


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