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

how to solve SQLite.SQLiteException: Busy issue.

$
0
0

In our Xamarin Forms application we are getting this particular issue SQLite.SQLiteException: Busy, specifically in iOS app, I feel this is because a database lock. Could any one please help me solving thos


Geolocation.GetLocationAsync doesn't work on Google pixel with only Emergency Location Service(ELS)

$
0
0

Hi,

I am using Xamarin Essential "Geolocation.GetLocationAsync" in my Xamarin forms project but this API doesn't work on "Google Pixel 2" if only Emergency Location Service is switched ON and "Google Location Accuracy" is switched OFF.

Any idea if "Google Location Accuracy" is mandatory to use "Geolocation.GetLocationAsync()" API?

Following are the Xamarin Forms and Xamarin Essentials packages which I am using on Google Pixel 2 (With Android 10 i.e. Android Q).

a. Xamarin forms version:

<package id="Xamarin.Forms" version="4.3.0.991221" targetFramework="monoandroid90" />

b. Xamarin Essentials version:

<package id="Xamarin.Essentials" version="1.3.1" targetFramework="monoandroid90" />

c. Android Version on Google Pixel 2:

Android 10.

Thanks.

SQLite Xamarin/C# inserting data

$
0
0

I am developing an application. I have connected my project to SQLIte, now I am trying to add an advert, which I am failing to do.

my SQLInterface

public interface ISQLiteInterface
{

    SQLiteConnection GetSQLiteConnection();

}

my Droid SQL

public class SQLiteDb : ISQLiteInterface
{
public SQLiteDb()
{

    }
    public SQLiteConnection GetSQLiteConnection()
    {
        var fileName = "Mydatabase.db";
        var dbpath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
        var path = Path.Combine(dbpath, fileName);
        var connection = new SQLiteConnection(path);


        return connection;
    }

}

}

my model

public class AdLogEntry
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string SellerName { get; set; }
public string Name { get; set; }
public List Pictures { get; set; }
public List

    public string Description { get; set; }
    public string Price { get; set; }
    public string  LoadedDate { get; set; }
    public string Location { get; set; }
    public int Age { get; set; }
}

public class Picture
{
    public string Id { get; set; }
    public string Url { get; set; }
    public byte[] Image { get; set; }
}
public class Video
{
    public string Id { get; set; }
    public string Url { get; set; }
    public byte[] ImageVideo { get; set; }
}

}

this is my task

private async void NextStep_Clicked(object sender, EventArgs e)
{
await SaveAdLog();
}

    private async Task SaveAdLog()
    {
        if (string.IsNullOrWhiteSpace(NameEntry.Text) || (string.IsNullOrWhiteSpace(PriceEntry.Text) || (string.IsNullOrWhiteSpace(LocationEntry.Text))))
        {
            await DisplayAlert("error", "fill all entries", "OK");
        }
        else {
            var adLogEntry = new AdLogEntry
            {
                Location = LocationEntry.Text,
                Price = PriceEntry.Text,
                Name = NameEntry.Text,

            };

///Here i get an error
var result = _adService.CreateAddLogEntry(adLogEntry); //ok
if (result == null)
{
await DisplayAlert("Gratulace", "", "OK");
App.Current.MainPage = new AppShell();
}

        };

    }

this is my advertservice

class AdService
{
private SQLiteConnection _conn;

    public AdService()
    {//ad had null exception here as well
        _conn = DependencyService.Get<Helpers.ISQLiteInterface>().GetSQLiteConnection();
        _conn.CreateTable<AdLogEntry>();

    }


    public string CreateAddLogEntry(AdLogEntry adLogEntry)
    {
        var detail =  _conn.Table<AdLogEntry>();
       var d1 = detail.Connection.Insert(adLogEntry);
       return "Thank you";
    }

}

}

Once I press the button nothing happens. When I try to debug it i get 'Object reference not set to an instance of an object.' once i approach SQL part, but it works with my login and sign up and I am doing that exactly the same

How can I remove the dividers in the AppShell flyout menu?

$
0
0

Currently, between my flyout items and normal menu items a divider is being displayed. I'd like to know how to remove this divider or at the very least change it's color. Anyone got any suggestions on how to do this? From what I've seen there are no properties that allow this kind of customisation.

App splash screen shows, OnCreate never called - dies with System.ArgumentNullException

$
0
0

Hello,

A co-worker had Visual Studio lock up yesterday. After restarting everything, he cannot run any of our apps. He is debugging on Android using emulators.

In each case, the app builds, deploys, and begins launching - the app splash screen image shows, but then it crashes out (application is in break mode) with the following exception:

System.ArgumentNullException: 'Value cannot be null.
Parameter name: key'

There is no stack trace information available (beyond [external code])

This appears to occur before OnCreate gets called, so it doesn't seem like a problem with our code.

He has:
- restarted VS
- rebooted
- deleted and re-created various android emulators
- cleaned, deleted bin and obj folders (builds successfully)
- cleared NuGet cache
- updated VS from 16.6.4 to 16.6.5

Other posts mention possible issues with XAML compilation - which we use, but the rest of the developers don't have any trouble.

Does anyone have any idea what might have gone awry? We are running out of ideas.

Thanks!

cannot show urhosharp surface multiple times

$
0
0

When the user open the view, navigate backwards and open the view a second time, the app crashes.
Any idea how to go around this issue?
Idealy, I would like to call:

skyUrho = await urhoSurface.Show<SkyUrho>(urhoApp);

only once in the constructor but that is not possible as it is an async call.

This is the code behind of the view:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

using AlmicantaratXF.ViewModels;
using AlmicantaratXF.Model;

namespace AlmicantaratXF.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class SkyUrhoSurface : ContentPage
    {
        private Sight currentSight;
        private SkyUrho skyUrho;
        private INavigation navigation;
        private Urho.ApplicationOptions urhoApp;
        public SkyUrhoSurface()
        {
            InitializeComponent();
            this.currentSight = null;
            urhoApp = new Urho.ApplicationOptions(assetsFolder: "Data");
        }
        public SkyUrhoSurface(Sight currentSight, INavigation navigation)
        {
            InitializeComponent();
            this.currentSight = currentSight;
            this.navigation = navigation;
            urhoApp = new Urho.ApplicationOptions(assetsFolder: "Data");
        }
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            skyUrho = await urhoSurface.Show<SkyUrho>(urhoApp);
          //SkyUrho skyUrho = new SkyUrho(new Urho.ApplicationOptions(assetsFolder: "Data"));
            skyUrho.PageVisible = true;
            skyUrho.StarSelection = (currentSight != null);
            buttonShootThisBody.BindingContext = skyUrho;
            labelLat.BindingContext = skyUrho;
            labelLon.BindingContext = skyUrho;
            labelAltitude.BindingContext = skyUrho;
            labelAzimuth.BindingContext = skyUrho;
            labelBodysName.BindingContext = skyUrho;
            labelBodysDirection.BindingContext = skyUrho;
            labelGPSStatus.BindingContext = skyUrho;
            //activityIndicator.BindingContext = skyUrho;
            activityIndicator.IsVisible = false;
            activityIndicator.IsRunning = false;
        }
        protected override async void OnDisappearing()
        {
            base.OnDisappearing();
            if (skyUrho != null)
                skyUrho.PageVisible = false;
        }
        void OnCheckBoxNamesChanged(object sender, CheckedChangedEventArgs e)
            {
                if(skyUrho!=null)
                    skyUrho.Names = e.Value;
            }
        void OnButtonShootThisBodyClicked(object sender, EventArgs args)
        {
            if(skyUrho!=null)
                if(skyUrho.SelectedStar!=null)
                    this.currentSight.StarID = (int)skyUrho.SelectedStar;
            navigation.PopAsync();
        }
    }
}

Renderers in Separate projects not working?

$
0
0

(PCL, XForm 1.3.1)

We have many apps. To handle this we have a common project for IOS and a common project for Android apps. See Screenshot.

If we put a Renderer in the Common IOS project, it is ignored. If we move the renderer to the main project it works.

How do we register a renderer so that it will work from a common project that all our apps can share?

[assembly: ExportRenderer(typeof(CleanListView), typeof(CleanListViewRenderer))]

namespace Common.IOS.Renderers
{
   public class CleanListViewRenderer :ListViewRenderer
    {
       protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
       {
           base.OnElementChanged(e);

           var tableView = Control as UITableView;
           if (tableView != null) tableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
       }
    }
}

Xamarin forms: Epubreader: System.AggregateException: 'One or more errors occurred

$
0
0

I am using epubreader (vers-one) NuGet package for parsing .epub files.

My Code:

string fileName = "SampleEPUB.epub";
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{fileName}");
EpubBook epubBook = EpubReader.ReadBook(stream);
foreach (EpubNavigationItem chapter in epubBook.Navigation)
{
    chapterDetails.Add(new ChapterDetails() { title = chapter.Title, htmlData = chapter.HtmlContentFile?.Content, subChapters = chapter.NestedItems });
}

For testing purposes, I have added the epub files on the project and parse the chapters like above. I need to change this implementation.

I am able to get the epub file links stored in our database. Now I need to parse the chapters of epub from the link. But when I use the link as the fileName in the above code I am getting the below exception:

System.AggregateException: 'One or more errors occurred. (Value cannot be null.Parameter name: stream)'

How can I solve this issue? One sample link is here. I have added a sample project here having .epub file links for the reference (epub file links are commented in the sample).


cannot delete app data, where is Environment.SpecialFolder.LocalApplicationData stored?

$
0
0

Something very strange,
I use sqlite-pcl-net v1.7.302-beta
I store datas in a sqlite database.
I debug my app on a android device.

I cannot delete the datas:

  • If I delete an item, when I start the app again, the item comes back.
  • If I delete the datas of the app, the datas come back.
  • If I delete the datas and unistall the app, the datas comes back?!!

This is my App.xaml.cs code:

        public static PositionsSightsDatabase PositionsSightsDB
        {
            get
            {
                if (positionsSightsDatabase == null)
                {
                    positionsSightsDatabase = new PositionsSightsDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PositionsSightsSQLite.db3"));
                }
#if DEBUG
                System.Diagnostics.Debug.WriteLine("db3 folder: " +  Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
#endif

                return positionsSightsDatabase;
            }
        }

The result is:
'/data/user/0/almicantarat.almicantarat/files/.local/share

When I browse my device, I don't find .local/share
Where are the datas stored? on my PC by VS?
Why is it impossible to delete the whole database?

CollectionView: SelectedItems not changing

$
0
0

my XAML:

<CollectionView ItemsSource="{Binding Items}" SelectedItems="{Binding ItemsSelected, Mode=TwoWay}"  SelectionMode="Multiple"
    ItemTemplate="{StaticResource ItemTemplateSelector}">
    <CollectionView.ItemsLayout>
        <GridItemsLayout Orientation="Vertical"
            Span="2" />
    </CollectionView.ItemsLayout>

</CollectionView>

my Code in my ViewModel

private ObservableCollection<Test> itemsSelected = new ObservableCollection<Test>();
public ObservableCollection<Test> ItemsSelected
{
    get
    {
        return itemsSelected;
    }
    set
    {
        if (itemsSelected != value)
        {
            itemsSelected = value;
        }
    }
}

I would expect that my ItemsSelected-Collection would contain all my Selected Items but it is always empty. When i fill it upfront with some Items, the behavior is as expected and the Items are preselected. I use the "TwoWay"-Binding but it only works "OneWay". I changed the ObservableCollection<> also to List<> but without any success.

What do I wrong ?

how to implement this the right way uploading images attach to json object?

$
0
0

Hi guys i have a web api that i use for my xamarin project.
in my web API project this is my controller
and in my model it looks something like this
now what i want is to upload a file/image to that object.

web api image + json in one go. WHATS THE PROPER WAY?

$
0
0

so this is my code for posting

public async Task AddProduct(int productid, string productCategory, string productColor, decimal unitPrice, string userId,byte[]image)
{

        var client = new HttpClient();

        var model = new Products
        {
            ProductId = productid,
            ProductCategory = productCategory,
            ProductColor = productColor,
           UnitPrice = unitPrice,
            UserId = userId,
            // Image = image <<<< DO I ADD THIS?






        };

        var json = JsonConvert.SerializeObject(model);

      var content = new StringContent(json);
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        var response = await client.PostAsync("http://192.168.1.6:44331/api/Products", content);

        return response.IsSuccessStatusCode;

    }

My question is this. and I'm really so confused about this part. in my view there will be add product. thats looks something like this

StackLayout>

    <Entry Text="{Binding ProductColor}" Placeholder="Enter Product Color"/>
    <Entry Text="{Binding ProductCategory}" Placeholder="Enter Product Category"/>
    <Entry Text="{Binding UnitPrice}" Placeholder="Enter Product Cost" Keyboard="Numeric"/>
    <Button Command="{Bingind AddProductCommand}" Text="Add Product"/>





</StackLayout>

in my view model i am just calling that service to a command to add the product. So my question is how can i slid the image there and post it in one go.
Or at least upload the image to azure blob storage and return it as uri then post it with a single command. Give me an idea on how to do that please. I've been reading so much topic about this. and all they teach is how to upload the image without the data along with it

Popup page with lottie return after animation is ready

$
0
0

Made a Popuppage with a Lottie animation .

Start the PopupPage with a ButtonClick

But how do i close it after the Lottie animation is done ?

async private void Button_Clicked(object sender, EventArgs e)
        {

           await PopupNavigation.Instance.PushAsync(new Plaatje());
        }


<?xml version="1.0" encoding="utf-8" ?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
              xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
    xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup" xmlns:forms="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"
                 x:Class="Lottietest.Plaatje">
    <pages:PopupPage.Animation>
        <animations:ScaleAnimation 
            PositionIn="Center"
            PositionOut="Center"
            ScaleIn="1.2"
            ScaleOut="0.8"
            DurationIn="300"
            DurationOut="400"
            EasingIn="SinOut"
            EasingOut="SinIn"
            HasBackgroundAnimation="True"/>
    </pages:PopupPage.Animation>
    <!--You can use any elements here which are extended from Xamarin.Forms.View-->
    <StackLayout>
        <forms:AnimationView 
                x:Name="AnimationView" 
            IsVisible="True"
                Animation="Nointernet.json" 
                AutoPlay="True" Loop="false"
            HeightRequest="120"
            WidthRequest="120"
            VerticalOptions="CenterAndExpand"
                HorizontalOptions="CenterAndExpand" />


    </StackLayout>
</pages:PopupPage>

how to add a list data into a picker

$
0
0

I have an API and i want to load API key into picker list how I do that

Does that InputTransparent="True" eve work?

$
0
0

In the past there were so many bugs regarding InputTransparent="True" and today seems to be still not working. I am trying InputTransparent=True on my page which Rg.popup page so, it should transfer the touch to the backround but, it doesnt work. Is there a know bug for that?




Display Switch coltrol between Xamarin form 3.5 and Xamarin form 4.6

$
0
0

I migration xamarin project from XF 3.x with to 4.6 with ios 11,12 and The currently displayed Switch control differs between the two versions, Can anybody tell me why? Thanks
XF 3.5

XF 4.6

Xamarin TabbedPage Issue

$
0
0

Hello everyone!
am having a major issue with xamarin tabbed page
There is one tabbed page in my xamarin project called TodayTabbedPage so by default in android, Tabs will be shown at the top side so I write following code in tabbed page XAML file to place them at bottom
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarItemColor="#262626"
android:TabbedPage.BarSelectedItemColor="#9900CC"
So It perfectly showing all tabs at the bottom
But whenever am calling another tabbed page instead of TodayTabbedPage the bottom tab line still shows
Hope this information is enough please help!!!

Upload png or jpg to a server

$
0
0

Hello everyone. I hope you guys are doing OK

I have a problem: I need to update the profile picture of the user.

I am using @JamesMontemagno plugin, to take the picture or take the picture


Everything work fine an dandy

I need to update the actual file png or jpg to the API i am using (my server does not support bytes)

I tried a couple of things:

1)

var img = new Image {
                Source = Path.GetFileName(mediaFile.Path)
            };

Witch produce this error: Self referencing loop detected for property 'ParentView' with type 'Xamarin.Forms.Image'. Path 'avatar.Source'.'

2) I tried to use the File updater plugin, witch internally use a POST (https://github.com/CrossGeeks/FileUploaderPlugin/tree/master/src) and my api dont support post

3) I tried to sent get the filename, using

var image = Path.GetFileName(mediafile.path) \\ but image is of type string

this is my code to send to server:

public static async Task<HttpResponseMessage> UploadFileAsync(string token, Dictionary<string, Image> avatarImg) {

            var jsonString = JsonConvert.SerializeObject(avatarImg);
            var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");

            Debug.WriteLine("http" + httpContent.ToString());

            using (HttpClient client = new HttpClient()) {

                var serverAdress = Constants.AVATAR;
                client.DefaultRequestHeaders.Add("Authorization", "jwt " + token);

                var response = await client.PutAsync(serverAdress, httpContent);

                return response;
            }

the reason I am Jsonising my diccionary, is becouse my format is

{ avatar: picture_goes_here }
4) I tried sending bytes, but the server dosent undertand bytes (and the server is not mine)

I researched a little bit and they recommend using WebClient, but I want to use http client (is newer and faster)

That for the help in advance

Carouselview not showing in iOS (Xamarin.Forms - 3.6.0.709228)

$
0
0

I am using xamarin.forms 3.6.0.709228. and I am trying to implement CarousleView which works fine in android but not showing in iOS. Is there any bug with Xamarin.Forms(3.6.0.709228) version ? or Is there any workaround to use CarouselView with Xamarin.Forms(3.6.0.709228) ?

tabs of tabbed pages have disappeared

Viewing all 89864 articles
Browse latest View live


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