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

PhotoImage Cropper

$
0
0

Hi I was using the Xam.Plugins.ImageCropper for the user to re-size / crop images from the media library before uploading them to the server. However it looks like this package isn't compatible with netstandard2.0 which is what I am using on my project now.

I'm a bit stuck - i have tried an alternative cropper (ImageCropper.Forms) however that just shows up a black popup when i try the example and doesn't really work.

Are there any other image croppers similar to Xam.Plugins.ImageCropper?

If not given that Xam.Plugins.ImageCropper has the source code available on GitHub what would I need to do to get this to netstandard2.0?


View gets unresponsive on loading data from multiple API calls

$
0
0

We adopted Xamarin for our company but we are badly stuck. It's been one week we are trying different things to resolve the issue. Basically the issue is our view calls multiple Restful req to API to generate the user form. Every time we go to the view it takes 4 to 5 seconds.
We tried everything such as opening separate thread, async methods but all in vain.
I don't understand why there is not a method that can be called when the view is completely displayed so that we can send API requests.
Please, someone, suggest something?

Binding Enum and using Preferences to save settings

$
0
0

Hi all,

I have come across another roadblock in my app, and would love to have your assistance.

I have my enum like this:

    public enum FuturesTakeProfitMode
    {
        ProfitByTarget,
        ProfitByPriceRange,
        ProfitByAny
    }

Using Xamarin Preferences, I have the following in the SettingsViewModel.cs:

        public List<string> ProftTakeModes
        {
            get
            {
                return Enum.GetNames(typeof(FuturesTakeProfitMode)).Select(x => x.SplitCamelCase()).ToList();
            }
        }

        public override FuturesTakeProfitMode TakeProfitMode
        {
            get => (FuturesTakeProfitMode)Preferences.Get(nameof(TakeProfitMode), (int)FuturesTakeProfitMode.ProfitByAny);
            set => SetPreference(nameof(TakeProfitMode), (int)value);
        }

In my XAML, I have:

            <StackLayout>
                <Label HorizontalOptions="Start">Profit take mode</Label>
                <Picker ItemsSource="{Binding ProftTakeModes}" SelectedIndex="{Binding TakeProfitMode, Converter={StaticResource IntEnum}}"></Picker>
            </StackLayout>

I get the following error when it is run:

System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

Without binding SelectedIndex, everything works, so I know something is wrong with the binding SelectedIndex.

            <StackLayout>
                <Label HorizontalOptions="Start">Profit take mode</Label>
                <Picker ItemsSource="{Binding ProftTakeModes}"></Picker>
            </StackLayout>

I was hoping you could help me figure out what the issue is please.

Thanks,
Michael

Xam.Plugin.Media ....Manifest file is failing to build/debug (Droid)

$
0
0

Everything was working. Updated VS (to fix iOS error)....now my Manifest is giving me an error:

unexpected element <provider> found in <manifest>.

Figured out the issue real quick. My manifest file goes from this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.myApp" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="28" />
    <application android:label="MyApp" android:icon="@drawable/Logo"></application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.CAPTURE_SECURE_VIDEO_OUTPUT" />
    <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
    <!--- this is where the "magic" will happen below --- comment not in code -->
    <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.myApp.fileprovider" android:exported="false" android:grantUriPermissions="true">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
    </provider>
</manifest>

To adding an "application" child and excludes the "provider".....

  <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
  ...
  <application android:label="MyApp" android:icon="@drawable/logo" android:name="android.app.Application" android:allowBackup="true" android:debuggable="true">
    <activity android:configChanges="orientation|screenSize" android:icon="@mipmap/icon" android:label="MyApp" android:theme="@style/MainTheme" android:name="md5a8c6c68a1c8ff1337a1f00940961e4a2.MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:configChanges="orientation|screenSize" android:name="md54fe4aef201482be7d95d72c0c9bf0b33.FilePickerActivity" />
    <activity android:configChanges="orientation|screenSize" android:name="md54cd65ac53ae710bff80022afc423e0f3.MediaPickerActivity" />
    <service android:name="md5dcb6eccdc824e0677ffae8ccdde42930.KeepAliveService" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" android:name="md5d630c3d3bfb5f5558520331566132d97.BatteryBroadcastReceiver" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" android:name="md5d630c3d3bfb5f5558520331566132d97.EnergySaverBroadcastReceiver" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" android:name="md5d630c3d3bfb5f5558520331566132d97.ConnectivityBroadcastReceiver" />
    <provider android:authorities="com.myApp.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="xamarin.essentials.fileProvider">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/xamarin_essentials_fileprovider_file_paths" />
    </provider>
    <receiver android:enabled="true" android:exported="false" android:name="md51558244f76c53b6aeda52c8a337f2c37.PowerSaveModeBroadcastReceiver" />
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.myApp.mono.MonoRuntimeProvider.__mono_init__" />
    <!--suppress ExportedReceiver-->
    <receiver android:name="mono.android.Seppuku">
      <intent-filter>
        <action android:name="mono.android.intent.action.SEPPUKU" />
        <category android:name="mono.android.intent.category.SEPPUKU.com.myApp" />
      </intent-filter>
    </receiver>
  </application>
...
  <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.myApp.fileprovider" android:exported="false" android:grantUriPermissions="true">
    <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
  </provider>
</manifest>

I literally have no idea what to do :#

Project/Environment info:
Xamarin.Plugin.FilePicker v.4.0.1.5
Xamarin.Forms v.4.0.0.425677 (otherwise error received - no access to folders XML folders in documentation)

How to create custom switch

$
0
0

Hello,
As am new to this platform I have no idea how to create a custom switch with text on it like this

How to use a grid in a scrollview in Xamarin.Forms?

$
0
0

Hi, I need to create a Grid in a scroll view. I created a version for the portrait and landscape mode. It should be scrollable in the portrait mode, but not in the landscape mode. The problem is if I add the scrollview it doesn't look like expected in landscape mode. Here is a gif with an example:

Here is my xaml code:

    <ContentPage.Content>
        <ScrollView>
            <Grid x:Name="myLayout" ColumnSpacing="0" RowSpacing="0">
                <BoxView x:Name="box1" BackgroundColor="Green"/>
                <BoxView x:Name="box2" BackgroundColor="Yellow"/>
                <BoxView x:Name="box3" BackgroundColor="Blue"/>
                <BoxView x:Name="box4" BackgroundColor="Gray"/>
            </Grid>
        </ScrollView>
    </ContentPage.Content>

And here the C# code, which handling the Orientation change:

    public partial class myPage : ContentPage
    {
        private double width,
                       height;

        public myPage()
        {
            InitializeComponent();

            width = this.Width;
            height = this.Height;
        }

        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);

            if (this.width != width || this.height != height)
            {
                this.width = width;
                this.height = height;

                UpdateLayout();
            }
        }

        private void UpdateLayout()
        {
            myLayout.ColumnDefinitions.Clear();
            myLayout.RowDefinitions.Clear();
            myLayout.Children.Clear();

            if (width > height) SetLandscapeLayout();
            else SetPortraitLayout();
        }

        private void SetPortraitLayout()
        {
            myLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            myLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            myLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            myLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });

            myLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            myLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });

            myLayout.Children.Add(view: box1, left: 0, top: 0);
            box1.HeightRequest = box1.Width;
            myLayout.Children.Add(view: box2, left: 1, top: 0);
            box2.HeightRequest = box2.Width;
            myLayout.Children.Add(view: box3, left: 2, top: 0);
            box3.HeightRequest = box3.Width;
            myLayout.Children.Add(view: box4, left: 3, top: 0);
            box4.HeightRequest = box4.Width;
        }

        private void SetLandscapeLayout()
        {
            myLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            myLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            myLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            myLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });

            myLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) });
            myLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });

            myLayout.Children.Add(view: box1, left: 0, top: 0);
            box1.WidthRequest = box1.Height;
            myLayout.Children.Add(view: box2, left: 0, top: 1);
            box2.WidthRequest = box2.Height;
            myLayout.Children.Add(view: box3, left: 0, top: 2);
            box3.WidthRequest = box3.Height;
            myLayout.Children.Add(view: box4, left: 0, top: 3);
            box4.WidthRequest = box4.Height;
        }
    }

Thanks in advance.

Xamarin is a really poor development experience

$
0
0

I recently started a new Xamarin Forms project in VS 2019. The idea of being able to create a cross platform mobile app using .NET sounded like an amazing idea, at least on paper.

In reality, this mature platform is still a pile of clunky trash. Connecting to the mac server feels like a team of new CS grads put it together. It constantly has issues whereby it can't install updates on the mac automatically, just fails to connect other times etc.

Once finally connected through restarting VS a couple times, opening a xib file just hangs for 2 mins and then comes up with an error.

Sigh. It drives me absolutely nuts how a company with the best and brightest can excel so much with Office and other software solutions, but completely suck at others.

Unfortunately none of the other solutions for X platform app development are any good at all. Xcode is a UX pile of crap, Flutter is super cool except someone thought it would be a fantastic idea to use Dart -- an esoteric language. So annoying at the state of development for mobile right now. Maybe someday a billion dollar company will come by and make something that works well.

Is it possible to integrate the HERE Maps Android/iOS SDKs into a xam.forms project?

$
0
0

Hi =)

So I believe there are two previous discussions on this:

https://forums.xamarin.com/discussion/43630/xamarin-binding-for-here-maps-problem
https://forums.xamarin.com/discussion/102803/binding-libary-incompatibility-here-maps-sdk

Currently I'm using: SDK Version: 3.11.2.82 (Premium)

The Android SDK comes as an .AAR, after extracting the .JAR, creating a Android binding library, and removing classes throwing errors:

<metadata>
  <remove-node path="/api/package[@name='com.here.android.mpa.pde']/class[@name='PlatformDataItem']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.pde']/class[@name='PlatformDataItemCollection']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.pde']/class[@name='PlatformDataResult']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='DiscoveryRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='TextSuggestionRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='TextAutoSuggestionRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='GeocodeRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='GeocodeRequest2']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='ImageMedia']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.search']/class[@name='PlaceRequest']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.mapping']/class[@name='MapOffScreenRenderer']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.streetlevel']/class[@name='StreetLevelModel']" />
  <remove-node path="/api/package[@name='com.here.android.mpa.streetlevel']/class[@name='StreetLevelOffScreenCapture']" />
  <remove-node path="/api/package[@name='com.here.odnp.util']/class[@name='OdnpIOUtils']" />
  <remove-node path="/api/package[@name='com.here.odnp.util']/class[@name='AlarmTimer']" />
  <remove-node path="/api/package[@name='com.here.odnp.util']/class[@name='AssetCopyTask']" />
  <remove-node path="/api/package[@name='com.here.odnp.wifi']/class[@name='WifiFilterRx']" />
  <remove-node path="/api/package[@name='com.here.odnp.wifi']/class[@name='WifiFilterTimestamp']" />
  <remove-node path="/api/package[@name='com.here.odnp.posclient.pos']/class[@name='PositioningSession']" />
  <remove-node path="/api/package[@name='com.here.services.playback.internal.util']/class[@name='PlaybackReader']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal.util']/class[@name='IRadioMapManager']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal.util']/class[@name='RadioMapManager']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal']/class[@name='IRadioMapManager']" />
  <remove-node path="/api/package[@name='com.here.services.radiomap.internal']/class[@name='RadioMapManager']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='StringNativeMap']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='StringNativeVector']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='NavigationManagerImpl']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='StringNativeVector']" />
  <remove-node path="/api/package[@name='com.nokia.maps']/class[@name='MapImpl']" />
  <remove-node path="/api/package[@name='com.here.sdk.analytics']/class[@name='HEREAnalytics']" />
</metadata>

I got my dll, but have a very good feeling it won't work =)

The iOS SDK comes as a NMAKit.framework, is there even a remote chance of finding a way to reference this in Xamarin?

Has anyone had any recent success with implementing HERE Maps in Xamarin?


Shell: How to add menu items from code?

$
0
0

I'd like to programmatically provide menu items to my Shell.
There seems to be a mechanism Shell.Items.Add(ShellItem), but the subclass MenuShellItem is protected.
Is there another way I can add menu items to my Shell?

FontAwesome fonts have disappeared on iOS

$
0
0

I have been using FontAwesome fonts in my app for about a year without any problems. Now, whenever I create a release build of the app, all I get are question marks instead of the icons. If I create a debug build to install on the phone or I run a release build on the simulator everything is fine. I have not changed any of the relevant declaration or definitions.

How can I fix this?

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 ?

Is it possible re-open app?

$
0
0
Hello guys, I’m developing app now, so user press button and then user’s geolocation pass to the server every set time, so I did it in background through Matcha.BackgroundService library, but I have a problem - when user cross country border there is small offline time and my app stop working maybe cuz of no network connection or waiting for roaming, so how I can re-launch it in iOS and android, I think in android I should use to broadcast service but I don’t know. Maybe it’s not needed to relaunch only keep it in background when no network and when it reveal, continue to pass geolocation
Sorry for my English:)
Thanks all

binding does not exist in current context - OnAppearing

$
0
0

Hi Everyone, Help please! :smile:

This is an accessibility question, and I can't seem to figure out the best way to go about it.
I want to set a variable that is bound to an entity (label.text in this case) in my OnAppearing method. i.e. I want to set the label when the page is loaded.

I've got my xaml page:

<?xml version="1.0" encoding="utf-8" ?>
...

         xmlns:local="clr-namespace:App13"
         x:Class="App13.MainPage">

<ContentPage.BindingContext>
    <local:myViewModel />
</ContentPage.BindingContext>

<StackLayout>

    <Label Text="{Binding myBindingEntry}" 

       HorizontalOptions="Center"
       VerticalOptions="CenterAndExpand" />

    <Button Text="Command Button"
            Command="{Binding btnCommand}"
            HorizontalOptions="Center"
            VerticalOptions="CenterAndExpand"
            />

</StackLayout>


'

And I've created another file, called myViewModel.cs :


using System.ComponentModel;
using System.Windows.Input;
using Xamarin.Forms;

namespace App13
{
class myViewModel : INotifyPropertyChanged
{

    string _myBindingEntry = "nothing!";

    public event PropertyChangedEventHandler PropertyChanged;
    public ICommand btnCommand { private set; get; }

    public myViewModel()
    {

        btnCommand = new Command(
            execute: () =>
            {
                myBindingEntry = "You have clicked the Command Button!";
                RefreshCanExecutes();
            }
            );


    }

    void RefreshCanExecutes()
    {
        ((Command)btnCommand).ChangeCanExecute();

    }

    public string myBindingEntry
    {

        private set
        {
            if (_myBindingEntry != value)
            {
                _myBindingEntry = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("myBindingEntry"));
            }
        }
        get
        {
            return _myBindingEntry;
        }


    }

}

}

And here's my code behind, which is where I want to set myBindingEntry:


using System.ComponentModel;
using Xamarin.Forms;

namespace App13
{
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
// I've tried declaring an instance of myViewModel class, to use later:
myViewModel fmyViewModel = new myViewModel();
public MainPage()
{
InitializeComponent();

    }

    protected override void OnAppearing()
    {

        // here is where I want to set the text of my Label.
        // i should be able to do it by assigning text to myBindingEntry

        // This generates 'The name 'myBindingEntry' does not exist in the current context.
        myBindingEntry = "this is set during OnAppearing";

        // or if I use this, I get:
        // Error CS0272  The property or indexer 'myViewModel.myBindingEntry' cannot be used in this context because the set accessor is inaccessible App13
        fmyViewModel.myBindingEntry = "using an instance of the view model!"

        base.OnAppearing();
    }

}

}

Highlight the image xamarin forms

$
0
0

Hi,
My question is about how we can highlight the captured image,

please help me to solve this issue.

System.ObjectDisposedException: 'Cannot access a closed Stream.'

$
0
0

This Exception occurs when I push a button so many time in a short time. Why this happen? If I do it slow, giving some time between press and press it everything is alright. The problem is if you do it quickly. It's about two button, one to increase (+) and the other to decrease (-) a value.


failed to open APK: Iteration ended.

$
0
0

I'm working in Xamarin forms project from past 6 months. Till now the development went well and after my windows 10 updated yesterday, My xamarin forms android is not getting build successfully. Its throwing error as "failed to open APK: Iteration ended."

Below are the two lines from output window

1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(155,3): warning APT2258: W/ziparchive(18668): Zip: Entry at offset zero has invalid LFH signature 929c1a24
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(155,3): error APT2096: failed to open APK: Iteration ended.

Please help in resolving this asap.

Animating scrollview items appear & disappear.

$
0
0

I'm trying to create some animations inside a CollectionView. This is when the items are added or when the items are removed.
I have looked for some animations tutorials however I have not seen an example being applied to the items inside the collectionview, how could I animate them?

Thanks!

Where is $(MSBuildExtensionsPath) located?

$
0
0

When creating a iOS Library porject and opening the csproj file I see <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" /> in the bottom. What is $(MSBuildExtensionsPath)and what is location of it?

output console data to ui in xamarin.forms

$
0
0

I'd like to be able to send the Application Output / debug info to an entry box (or whatever works).

I tried using an Editor with and rerouting the console.out to it, but there seem to be major roadblocks with vague documentation. How can I catch this data and send it to my ui?

Thanks for reading :#

Xamarin Forms: How to create an Epub Viewer in Xamarin Forms?

$
0
0

I am trying to implement an epub viewer in xamarin forms like the below video.

Video Link: https://drive.google.com/file/d/1jW33lstCXqwC35siYklLoXAxItWpQG8c/view?usp=sharing

At first, I need to show the TOC of the book. If taps any chapter in TOC need to show that chapter on the UI. The total chapters and current chapter details are added at the bottom of the page. We can change the font size, font style, light and dark theme, and horizontal and vertical swiping features. Also able to hear the chapter in audio voice. Please have a look at the above video.

This is the native Android implementation. I need to do this feature in xamarin forms, following are my queries.

  1. Is xamarin offer an epub viewer like this? Or I need to do all these features custom?
  2. I tried EpubReader.Cross NuGet package, but it has no TOC list.
  3. How can I change the font size and font style like the video?
  4. For audio voice feature I can use text to speech feature, but when reading the book by voice how can I highlight the text?
  5. There is a package named epubReader, it has a TOC list. But when I try to install it to the project, I am getting this error.
Viewing all 79144 articles
Browse latest View live


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