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

Size of .APKs just ballooned!

$
0
0

A few days ago I updated to VS 2019 v.16.2.1 and Xamarin.Android SDK v.9.3.1.0 and I've noticed that the size of my APKs has ballooned by about 50% while the iOS packages have remained unchanged. My first thought was that I'd changed my compiler or linker settings, but those are still d8/r8 (Sdk and User Assemblies) and I'm seeing the problem even when rolling back to an old project file. I'm also still targeting the same architectures.

I suspect there may be a linker bug that was introduced.

Here's a diff of two builds. The changes I introduced that day were minor, and so I wasn't expecting the size increase. There's also no reason that all the SDK assemblies would have increased in size.

Has anyone else seen this?


Using Grouping in listview, whose content is saved in an SQLite database

$
0
0

I want to group the data I have saved in an SQLite database by the content of one column from this database and load them in a listview. I have partly figured out how to load a column. I used this function but it only returned the 3 entries I have and not the right dates. It instead returned 01/01/01/0001 00:00:00.
public Task<List> GetCalendarEntriesStartDates()
{
return calendarentrydatabase.QueryAsync("SELECT DISTINCT [CalendarEntryStartDate],[CalendarEntryId] FROM [CalendarEntry] ORDER BY [CalendarEntryStartDate]");
}
I also find out how to create a class for the grouped content, but I don't know how to load the content in these groups.
public class CalendarGroup : IEnumerable
{
public DateTime CalendarEntryStartDate { get; set; }
public ObservableCollection CalendarEntries { get; set; }
IEnumerator IEnumerable.GetEnumerator()
{
return CalendarEntries.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return CalendarEntries.GetEnumerator();
}
}
Can someone explain to me how to do this, by using SQLite-net-plc?

Error on resolve reference

$
0
0

Hello, Im getting and error and I don't know how to fix it. I've tried a lot of things, so I've come here. Error: Error Can not resolve reference: System.Configuration, referenced by tournamentMaker > TournamentMaker.Domain > EntityFramework. Please add a NuGet package or assembly reference for System.Configuration, or remove the reference to tournamentMaker`. tournamentMaker.Android
Thank you,
Pablo Hervás

Build issues lattest release visual studio 2019

$
0
0

Is anyone else having build issues on the latest release for campaign 4 and visual studio?

please how can i resolve Could not load assembly 'Allschooldesk, Version=0.0.0.0, Culture=neutral,

$
0
0

Please see the stack trace

            The "ResolveLibraryProjectImports" task failed unexpectedly.
    System.IO.FileNotFoundException: Could not load assembly 'Allschooldesk, Version=0.0.0.0, Culture=neutral, 
             PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
    File name: 'Allschooldesk.dll'
       at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
       at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName)
       at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection`1 jars, ICollection`1        
                   resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments)
       at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
       at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
       at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Allschooldesk.Android           

Grid row height auto leaves blank space

$
0
0

As you can see on the picture, pug image (with red background) is smaller, that grid row height(which is set as Auto).
How can I make grid cell fit my image?

Layout is pretty straightforward:

    <Grid ColumnSpacing="0"
          RowSpacing="0"
          Margin="0"
          Padding="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.5*" />
            <ColumnDefinition Width="0.5*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Label Text="Test"
               Grid.Column="1" />
        <Label Text="Test"
               Grid.Row="1" />
            <Image Source="{local:ImageResource PugSoundboard.images.pugface-1.png}" BackgroundColor="Red" VerticalOptions="Center"/>
    </Grid>

Size of .APKs just ballooned!

$
0
0

A few days ago I updated to VS 2019 v.16.2.1 and Xamarin.Android SDK v.9.3.1.0 and I've noticed that the size of my APKs has ballooned by about 50% while the iOS packages have remained unchanged. My first thought was that I'd changed my compiler or linker settings, but those are still d8/r8 (Sdk and User Assemblies) and I'm seeing the problem even when rolling back to an old project file. I'm also still targeting the same architectures.

I suspect there may be a linker bug that was introduced.

Here's a diff of two builds. The changes I introduced that day were minor, and so I wasn't expecting the size increase. There's also no reason that all the SDK assemblies would have increased in size.

Has anyone else seen this?

How to add SearchBar and NavigationPage.PrefersLargeTitles IOS using xaml?

$
0
0

Hello! How to add SearchBar and NavigationPage.PrefersLargeTitles IOS using xaml?


Unable to get installed UWP package to work - crashes on launch

$
0
0

I commented on another thread - https://forums.xamarin.com/discussion/57179/uwp-immediate-crash-in-release-mode - and then realised it had an accepted answer, so may not get looked at as a result, so raising a new thread for this issue. The "accepted answer" for the other thread doesn't work for me (the only thing I haven't tried, from the whole thread in fact, is adding assemblies per some quoted links which are now no longer valid). Even trying it in debug mode doesn't work. App works fine in both Debug and Release in VS,but when I create an app package and try it from there the app crashes after starting, with
"Faulting module name: Windows.UI.Xaml.dll, version: 10.0.17763.404, time stamp: 0x5c3c199a
Exception code: 0xc000027b
Fault offset: 0x008dc0f1
Faulting process id: 0x1a64"

thanks,
Donald

Hi, I have a CollectionView in my project. The collectionview implements a DataTemplateSelector and

$
0
0

Hi, I have a CollectionView in my project. The collectionview implements a DataTemplateSelector of 8 templates. That works fine. My challenge is that the template views have buttons and I need to get the button click events. I have tried this

                   <ImageButton 
                          Command="{Binding BindingContext.DisplayMessage, Source={x:Reference ShopList}}"
                          CommandParameter="{Binding.ProductId}"/>

But because the template and the hosting CollectionView are in different files I get error of not getting reference to ShopList which is the name given to the CollectionView. Please how do I get this to work with CollectionView and template containing the button in different files? Thank you.

Xamarin Forms Android App Connect/Communicate via USB to PC

$
0
0

Hello,
I am working on an Android (Xamarin Forms) application, and have a need to communicate with a Windows PC. This communication NEEDS to happen over USB cable. I googled this problem and found a couple of incredibly similar projects anotherlab's UsbSerialForAndroid, and lusovu's XmarinUsbSerial.

I am using anotherlab's project as a starting point on how to get android -> pc usb comms working, but am running into the problem of never being able to find any devices when the tablet is plugged into the PC. I have tried using a regular USB cable as well as an OTG cable without any luck. I just can't figure out why the device list is empty when using the following lines of code:

    usbManager = GetSystemService(Context.UsbService) as UsbManager;
    IDictionary<string, UsbDevice> devices = usbManager.DeviceList;

I'm thinking it might be a problem with the drivers it's using but I have no clue as to how to get the vendor id or the product id of the usb host controller in my laptop (done a quick search). Could it be something else?

I can connect to an Arduino device using the OTG cable and can get the project working with it, but I need it to work with a PC not an Arduino.

If anyone has any ideas I would be grateful,
Thanks

Binding my data classes to my forms...

$
0
0

Hello all! Sorry this seems to be a subject beaten to death, but I have tried a number of google searches, and none of the "Fixes" have fixed my problem...

I want to perform what should be the simple task of binding the data class to the form fields. Let's say I open the view with an existing record from the SQLite table, I want the viewModel object to pre-populate the form with the data.
Likewise, If I click the "Get my location" button (code not here) I would like the Lat / Long to pre populate with the data I received.

I now I can do all this programmatically, using the x:Name="MyName" in the XAML then MyName.Text = "Hello"; in the code. I would like to make the binding do the job it was intended for.

My code is pretty psychotic so here is a stripped down sample of what I have tried most recently to make this work.
I've tried using the
BindingContext = viewModel;
and I also tried
BindingContex = viewModel.Data;

I've tried
<Label Text="{Binding Name}">
<Label Text="{Binding Data.Name}">
<Label Text="{Binding viewModel.Data.Name}">

Yes desperation had set in... lol

As always, I appreciate any assistance immensely!

Cheers!

Here are those samples....

 public class Items: EventParent, INotifyPropertyChanged
    {
        private int _id;
        [PrimaryKey, AutoIncrement]
        public int Id
        {
            get { return _id; }
            set
            {
                this._id = value;
                OnPropertyChanged(nameof(Id));
            }
        }
        private string _path;
        public string Path
        {
            get { return _path; }
            set
            {
                this._path = value;
                OnPropertyChanged(nameof(Path));
            }
        }
        private byte[] _image;
        public byte[] Image
        {
            get { return _image; }
            set
            {
                this._image = value;
                OnPropertyChanged(nameof(Image));
            }
        }
}

In my viewModel I am building a viewModel Class with this custom type in it

    namespace App.ViewModel
{
    public class ItemViewModel : BaseViewModel
        {
            ......
            public Item Data { get; set; }

            public ItemViewModel(Item item= null)
            {
                Data = (item == null ? new Item():item);
        .....
            }
        }
}

In my actual View....

    namespace App.Views
    {
        [XamlCompilation(XamlCompilationOptions.Compile)]
        public partial class AddItem: ContentPage
        {
            private ItemViewModel viewModel;

           ...

            public AddItem(ItemViewModel viewModel)
            {
                InitializeComponent();
                BindingContext =  ( viewModel == null ? new RangeViewModel():viewModel);
                InitializeForm();
            }
            public AddRange()
            {
                InitializeComponent();
                viewModel = new ItemViewModel();
                BindingContext = viewModel;
        InitializeForm();
            }
       public initializeForm()
       {


       }
        }

Finally, in my View XAML file

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage
        x:Class="GunTool.Views.AddRange"
        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">
        <ContentPage.Content>
                    <Label
                        x:Name="MyField"
                        d:Text="34.23276893452"
                        Text="{Binding Path=Name}" />
    </ContentPage.Content>

Handle Connectivity Exception

$
0
0

Hello, I am creating a transmission application for a radio, for this I am using the XamarinMediaManager plugin to reproduce the transmission and additionally through HttpClient I get the song covers and I show them in the app, so far in theory everything is fine.

The problem that arises is that where I am I have huge but huge connectivity problems, so when the internet goes down, the application closes unexpectedly (crash).

To find out exactly the fault I have used the Microsoft App Center through Diagnostic I have obtained 2 causes.

The first is that when the internet goes down and at that moment the HttpClient is being used to obtain the cover, it will crash either by "System.Net.Sockets.SocketException: Network subsystem is down", "System.IO.IOException: Remote prematurely closed connection. "," System.Net.Http.HttpRequestException: Network is unreachable "or some Timeout. To try to avoid the Crash, I have tried with Try and Catch, with the Connectivity pluging and also with the Xamarin Essentials plugin, but they do not always detect when the internet goes down, finally I have tried with Polly to retry and try to stop the expecion

retryPolicy = Policy
                .Handle ()
                .Or ()
                .Or ()
                .OrResult (r => httpStatusCodesToRetry.Contains (r.StatusCode))

but nothing seems to work to prevent the app crash.

And second, similarly it happens to me with the XamarinMediaManager plugin, but the latter I think is more complex to avoid the app crash, since I think it should be handled inside the plugin, even so I also try to detect when there is no internet to place pause and avoid the error (this is notified in the github of plugin # 552) some of the errors that appear to me when the internet falls are:

1) MediaExtractor.ExtractMetadata (MediaManager.Media.IMediaItem mediaItem)
C: \ Users \ mhvdi \ Documents \ OpenSource \ XamarinMediaManager \ MediaManager \ Platforms \ Android \ Media \ MediaExtractor.cs, line 32
Java.Lang.RuntimeException: setDataSource failed: status = 0x80000000

2) MediaItemExtensions.GetImageBitmapFromUrl (System.String url)
C: \ Users \ mhvdi \ Documents \ OpenSource \ XamarinMediaManager \ MediaManager \ Platforms \ Android \ Media \ MediaItemExtensions.cs, line 202
System.Net.WebException: The operation has timed out.

3) MediaItemExtensions.GetImageBitmapFromUrl (System.String url)
C: \ Users \ mhvdi \ Documents \ OpenSource \ XamarinMediaManager \ MediaManager \ Platforms \ Android \ Media \ MediaItemExtensions.cs, line 201
System.Net.WebException: Error: NameResolutionFailure

4) MediaItemExtensions.GetImageBitmapFromUrl (System.String url)
C: \ Users \ mhvdi \ Documents \ OpenSource \ XamarinMediaManager \ MediaManager \ Platforms \ Android \ Media \ MediaItemExtensions.cs, line 204
System.Net.WebException: Error getting response stream (ReadDoneAsync2): ReceiveFailure

5) MediaItemExtensions.GetImageBitmapFromUrl (System.String url)
System.Net.WebException: The operation has timed out.

In summary, I would like you to please give me some idea or advice on how I can handle or prevent the application from closing when the internet does not suddenly drop. Perhaps there is some more robust pattern or mechanism to handle these types of exceptions.

Thank you so much.

Listview Itemappearing

$
0
0

Hi. How can i do binding for my listview Itemappearing? It need for add more items in my listview.

Not generating xaml.g.cs files

$
0
0

I've just updated an old PCL project to .NET Standard (2.0) and it has now stopped generating the xaml.g.cs files. Consequently none of the xaml pages compile, and it can't find any of the variables in the xaml.cs file that were declared in the xaml files. It also can't find InitializeComponent() in the xaml.cs files.

The name 'InitializeComponent' does not exist in the current context.

I've tried adding a new xaml file and it also doesn't generate the xaml.g.cs file, altho when I try the same thing in a newly created .NET Standard project it all works fine.

I've been playing around a bit with the .csprog file, trying to make it mimic the project that works, but that hasn't made any difference either.

Does anyone have any suggestions about what could be going wrong.


How to reduce space between image and buttontext in a button

$
0
0
I need a button with image. I set imagesource property in button control. It works good but there is space between image and button text.
How to reduce the space. Please help on this.

Note: I am using XamarinForms 4.1 version latest

Religious Compass not working --- Help!

$
0
0

Hi,

I am trying to make a religious compass pointing to holy places

But as you can see in the attached it is not working properly

My app (with white background) is pointing to a wrong direction where the other photo shows another published app showing the correct location

Also, how can I make the accuracy up to 90 degree only because it won't be correct if it exceeded 90 degree?

Sample app and the screenshots are attached

Thanks,
Jassim

Invoke on UI Thread

$
0
0

Is it possible to run code on the UI thread without creating a renderer.

OnBackButtonPressed crashes android app

$
0
0

I have a crash report in my app center and it shows that OnBackButtonPressed throws exception crash for some users. This page is on masterdetailpage, so only way to navigate this page is using master of masterdetailpage. Any idea what could be the problem? I am only seeing this problem on Android app.

I see that there is bug report 3 years ago and workaround but this workaround is not solution for me and I am on xf4.0, could that be that it is still bug? because i dont see anything wrong with my code. I cannot even reproduce it on my android 9 device.
https://forums.xamarin.com/discussion/81793/back-button-from-causes-crash-on-android-when-page-is-masterdetail

     protected override bool OnBackButtonPressed()
            {
                try
                {
                    vm = (myPageModel)this.BindingContext;

                        Device.BeginInvokeOnMainThread(async () =>
                              {
                                  await vm.navigateBackButton();
                              });

                    return true;
                }
                catch (Exception ex)
                {

                    return false;
                }
            }

Exception:

Xamarin Exception Stack:
System.NullReferenceException: Object reference not set to an instance of an object
  at myApp.myPage.<OnBackButtonPressed>b__12_0 () [0x00011] in <d01445d6e9ae402b9455a7f527f84cbd>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <d6eff0560e354d9e932db3548bf1983e>:0
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <71397d308a1c40929b76149f37c9290e>:0
  at Java.Lang.Thread+RunnableImplementor.Run () <0x72f5de3eb8 + 0x0004b> in <71397d308a1c40929b76149f37c9290e>:0
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <71397d308a1c40929b76149f37c9290e>:0
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.39(intptr,intptr)

Behavior issue

$
0
0

Good aftnernoon ladies and gents.

My situation is as followed:

  • Portable project with a Custom Behavior in it.
  • Regular Xamarin project which has a reference to the Portable project in the Shared code project.

The Behavior in question (it's based on a Custom Entry which i named Entry :) )

using System;
using System.Windows.Input;
using XamarinForms = Xamarin.Forms;

namespace ChipSoft.Mobile.Core.Presentation.Xamarin.Behaviors
{
    public class CompletedEventBehavior : XamarinForms.Behavior<Entry>
    {
        public static readonly XamarinForms.BindableProperty CommandProperty = XamarinForms.BindableProperty.Create<CompletedEventBehavior, ICommand>
        (
            p => p.Command,
            null,
            propertyChanged: OnCommandChanged
        );

        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        public static void OnCommandChanged(XamarinForms.BindableObject bo, ICommand oldValue, ICommand newValue)
        {
            bo.SetValue(CommandProperty, newValue);
        }

        protected override void OnAttachedTo(Entry entry)
        {
            entry.Completed += OnEntryCompleted;
            base.OnAttachedTo(entry);
        }

        protected override void OnDetachingFrom(Entry entry)
        {
            entry.Completed -= OnEntryCompleted;
            base.OnDetachingFrom(entry);
        }

        void OnEntryCompleted(object sender, EventArgs args)
        {
            if (Command != null)
            {
                if (Command.CanExecute(null))
                {
                    Command.Execute(null);
                }
            }
        }
    }
}

Xaml usage:

<Entry.Behaviors>
   <behaviors:CompletedEventBehavior Command="{Binding LoginCommand}"/>
</Entry.Behaviors>

The LoginCommand does what it says it does :)

The error I am getting complete with Stacktrace:

A first chance exception of type 'System.InvalidOperationException' occurred in Xamarin.Forms.Core.DLL

Additional information: bindable not an instance of AssociatedType

at Xamarin.Forms.Behavior.Xamarin.Forms.IAttachedObject.AttachTo(BindableObject bindable)

The question is quite simple, why doesn't this work?
It is based on several posts online and it worked before we moved the Behavior itself to the portable project.
We are using the latest Xamarin.Core and Xamarin.Forms versions.

Viewing all 91519 articles
Browse latest View live


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