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

Visual Studio 2019 Preview 2: Can't create Windows UWP project using Xamarin.Forms

$
0
0

Hello, I'm learning to develop both Windows(UWP) and Android app using Xamarin.Forms. When I heard the news that Visual Studio 2019 Preview 2 came to availability, I decided to give it a try.

However, when I tried to create a new Cross-Platform Xamarin.Forms project for both Windows and Android, 'Windows' checkbox was missing on 'select a template' screen, which is currently available on Visual Studio 2017.

Why is that? I know that I can add an Windows project later on after I create an Android-only project, but that process is kinda annoying. Are Microsoft and their Xamarin team going to drop Windows support in the later iteration of Visual Studio and Xamarin? or will they reactivate the option later on?


Scanning App in Xamarin forms using custom renderer

$
0
0

I have to implement a Scanning App in Xamarin forms. I want to use AVFoundation for iOS Google Vision for Android. can you please tell me how to achieve it. I tried ZXing but It is creating issue with some of the QRcode, if it is complex of not clear.

FFImageLoading Android 4.2 Not Show

$
0
0

hi
4.2 or 4.3 Not Show

not showing Source
show LoadingPlaceholder or ErrorPlaceholder

TabbedPage - Content appears under Bottom Tabs

$
0
0

Our TabbedPage has pages with ListViews. The last item in the listviews appears under the bottom tab when the listview is scrolled to the end. Is there a way to tell the TabbedPage not to have content under the bottom tab so we can see all the Listview content when scrolled to the end?

Photo:

Shell Bottom Tabs, how do I get full color icons?

$
0
0

I'm not a fan of the monochrome icons, is there a way to get it to use the full color icons there?

upload an image to a FTP server

$
0
0

Hello Everyone.

I'm working on a app and i need to upload an image to a FTP server in it.
I'm using FluentFtp for this in which i have two ways to upload

  1. FtpObj.Upload(FileStream, Remotepath);
  2. Ftp.UploadFile(localPath,remotePath)

I have implemented an iPhotoPicker Service(Image Attached) to get both Stream and Image path
but i getting different path on different apps(File Manager, Photos, Gallery) Like
"/external/images/media/35410"
"/-1/1/content://media/external/images/media/35020/ORIGINAL/NONE/image/jpeg/559573774"
"/document/image:1234241"
None of these paths are working.
So I need Image picker that will give me correct and same path regardless of App you are selecting image with.
P.S If possible Add Capture photo from camera directly

Signup and signin on xamarin

$
0
0
Hi, i want to create a Page ti register an user on my xamarin.forms app. I want to use AWS cognito bit there is no tutorial on internet, so what can i do to create this two page ?

Xamarin.Essentials Preferences do not work anymore (debug mode)

$
0
0

Hi,

I had some trouble with a piece of code which was not working (my bad), and I restored it successfully. This code uses Preferences from Xamarin Essentials, and as I thought the problem was with it, I updated it with NuGet in the whole solution.

But now my problem is fixed, and I still face an issue that I can't resolve... The code works because I made tests, but I am not able to retrieve preferences at startup. Yet, preferences are correctly set at runtime, I checked its value in the app !

So, is it a known issue with Preferences ? It does not work in debug mode, neither release mode...

Precision : as I changed this piece of code to make it smarter and to preserve MVVM, I already tested Preferences and it worked very well even in debug mode... But as I updated it before being able to build again, I can't compare...

Thanks,
Galactose

(In case it's not a known issue, here is my code:

using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using Xamarin.Essentials;
using CardioCALC.Models;

namespace CardioCALC.ViewModels
{
    public sealed class FavoritesViewModel : ViewModelBase
    {
        /*
         *  SINGLETON :
         *      - Instance
         *      - Constructors to avoir other instance and be thread-safe
         */
        public static FavoritesViewModel Instance { get; } = new FavoritesViewModel();

        static FavoritesViewModel()
        { }

        private FavoritesViewModel()
        {
            this.Favorites.CollectionChanged += OnFavoritesSaveChanges; // Autosave
        }


        /*
         *  CLASS : classic properties and methodes to be used in the singleton instance
         *      - separator : constant char for serialization/deserialization
         *      - favoritePreferenceKey : constant string to be used as Key in Xamarin.Essentials.Preferences
         *      - Methods to Add/Remove/Toggle favorites (update list AND the score instance)
         */

        private const char separator = ',';
        private const string favoritePreferenceKey = "favorites";

        public ObservableCollection<Score> Favorites { get; private set; } = new ObservableCollection<Score>();
        public ObservableCollection<Score> Scores { get => ScoreListViewModel.Instance.Scores; }

        public void ToggleFavorite(Score score)
        {
            if (score.IsFavorite) this.RemoveFavoriteAndUpdate(score);
            else this.AddFavoriteAndUpdate(score);
        }

        public void AddFavoriteAndUpdate(Score score)
        {
            score.IsFavorite = true;
            if (!this.Favorites.Contains(score)) this.Favorites.AddSorted(score);
        }

        public void RemoveFavoriteAndUpdate(Score favorite)
        {
            favorite.IsFavorite = false;
            this.Favorites.Remove(favorite);
        }

        // Auto-save favorites list with event
        private void OnFavoritesSaveChanges(object sender, NotifyCollectionChangedEventArgs e)
        {
            this.SaveFavorites();
        }


        /*
         *      Methods to Save/Load favorites from database/preferences(with serialization/deserialization)
         */
        public void LoadSavedFavorites()
        {
            this.Favorites.Clear(); // Clear favorites (ie. to reload favorites after locale change in ScoreListViewModel)

            string favorites = Preferences.Get(favoritePreferenceKey, "");
            if (favorites == "") return;

            foreach (Score favorite in this.Deserialize(favorites))
            {
                this.AddFavoriteAndUpdate(favorite);
            }
        }

        public void SaveFavorites()
        {
            if (this.Favorites.Count > 0)
                Preferences.Set(favoritePreferenceKey, this.Serialize());

            else Preferences.Remove(favoritePreferenceKey);
        }

        // Serialize favorites list into string format
        public string Serialize()
        {
            if (this.Favorites.Count < 1) return "";

            string favorites = "";
            foreach (Score favorite in this.Favorites)
            {
                favorites += $"{favorite.PageName}{separator}";
            }
            return favorites.TrimEnd(separator);
        }

        // Deserialize favorites list from string to restore Collection
        public ObservableCollection<Score> Deserialize(string favorites)
        {
            ObservableCollection<Score> favoritesList = new ObservableCollection<Score>();
            foreach(string favorite in favorites.Split(separator))
            {
                favoritesList.Add(this.Scores.FirstOrDefault(s => s.PageName == favorite)); // this.Scores contains all scores
            }
            return favoritesList;
        }
    }
}

Cannot run android emulator from VS : stuck with "Select device" icon

$
0
0

Hi, after hours of research, i'm a bit disappointed. I found many similar cases but most of them were old or not solved.

When I start VS, I'm unable to select any Android emulator to deploy my app, stuck with "select device".

Since the beggining I used the same emulator, and everything was working fine. This problem appeared suddenly.

I can run emulators from the Android emulator manager perfectly but I am not able to deploy my app on it, I think VS cannot detect it running.
When I press F5 or Ctrl+F5, VS is asking me to create a new emulator (wich I do a few times but ye, when I run it, not detected)

I tried multiple things :

  • Delete/Re-install emulators. In my project I'm working on Pie 9.0 - Api, I also tried Android 10 and even Android 8.1 emulators, same problem.
  • Factory reset emulator
  • Use adb kill-server/start server (I cannot use "Restart ADB server" in Tools/Android, so I did it manually from console. I don't know why...)
  • Set my .Android as starting project

My case seems similar to "Visual Studio gets stuck trying to deploy the app to the emulator or the emulator does not appear as a debug target in other IDEs" from the "Troubleshoot the Visual Studio Emulator for Android" microsoft page, but to fix it, I need to use regedit and edit a key in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools, but I do not have Android SDK Tools folder.

The only things that partially solved my problem :

  • Full re-installation of Visual Studio
  • Re-install Android SDK Tools and Android Emulator from SDK package manager

Both allowed me to use my emulator as before. But when I restart my computer, the problem occurs again, with "Select device" stuck.
After mutliple tries, it is the only way I found to fix this problem. So the problem is should be caused by SDK packages.

I'm in trouble with it and tired spending hours to reinstall SDK Tools everytime.
Does someone have the same case ? Any idea to solve it ?

Increase performance of CollectionView using Grid with configurable columns as ItemTemplate

$
0
0

Dear Xamarin Community,

I have recently converted all my Listviews to Collectionviews to increase the performance. This works great, but I'm looking to increase the performance even more when it comes to the layout used as the ItemTemplate.

Specifications:

  • Multiple columns where the width for each column is configurable. I need to be able to change the width on all columns and also hide columns by setting the width to 0. In the same way it should be possible show columns with default width 0 by setting the width.
  • The widht of the columns should be relative to each other to not create a massive breaking change in configurations. The width of each column is today binded to a GridLength property that uses GridLength.Star for width > 0 and GridlLength.Absolute if the width is 0.
  • The height must be dynamic. Each column consist of a single label. All the information in each label must be shown, so the height needs to adapt to the length of the labels.
  • It is desirable to be able to add custom columns in runtime. This is not possible in the current solution, but there is a high demand for this feature. This is not a part of increasing the performance, and not an absolute must at this time, so don't be shy to shout out some performance tips if you don't have a solution for this part.

Current Implementation:

<CollectionView x:Name="OrderCollectionView" Grid.Row="2" Grid.Column="0" ItemsSource="{Binding Orders}" SelectedItem="{Binding SelectedOrder, Mode=TwoWay}" SelectionMode="Single" SelectionChangedCommand="{Binding SelectionChangedCommand}">
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <CustomGrid.ColumnSpacing="5" Padding="5,10,5,0">
                <CustomGrid.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding Source={x:Reference OrderCollectionView}, Path=BindingContext.ItemTappedCommand}" CommandParameter="{Binding .}"/>
                </CustomGrid.GestureRecognizers>
                <CustomGrid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="6"/>
                </CustomGrid.RowDefinitions>
                <CustomGrid.ColumnDefinitions>
                    <ColumnDefinition Width="{Binding OrdernoColumnWidth, Mode=TwoWay}" BindingContext="{Binding Source={x:Reference OrderCollectionView}, Path=BindingContext}"/>
                    <ColumnDefinition Width="{Binding CustomernoColumnWidth, Mode=TwoWay}" BindingContext="{Binding Source={x:Reference OrderCollectionView}, Path=BindingContext}"/>
                    <ColumnDefinition Width="{Binding CustomernameColumnWidth, Mode=TwoWay}" BindingContext="{Binding Source={x:Reference OrderCollectionView}, Path=BindingContext}"/>
                    <ColumnDefinition Width="{Binding OrderlinesColumnWidth, Mode=TwoWay}" BindingContext="{Binding Source={x:Reference OrderCollectionView}, Path=BindingContext}"/>
                    <ColumnDefinition Width="{Binding PackagesColumnWidth, Mode=TwoWay}" BindingContext="{Binding Source={x:Reference OrderCollectionView}, Path=BindingContext}"/>
                    <ColumnDefinition Width="{Binding WeightColumnWidth, Mode=TwoWay}" BindingContext="{Binding Source={x:Reference OrderCollectionView}, Path=BindingContext}"/>
                </CustomGrid.ColumnDefinitions>
                <Label Text="{Binding Path=[orderno]}" Grid.Column="0" FontSize="17" VerticalTextAlignment="Center"/>
                <Label Text="{Binding Path=[customerno]}" Grid.Column="1" FontSize="17" VerticalTextAlignment="Center"/>
                <Label Text="{Binding Path=[customername]}" Grid.Column="2" FontSize="17" VerticalTextAlignment="Center"/>
                <Label Text="{Binding Path=[orderlines]}" Grid.Column="3" FontSize="17" VerticalTextAlignment="Center"/>
                <Label Text="{Binding Path=[packages]}" Grid.Column="4" FontSize="17" VerticalTextAlignment="Center"/>
                <Label Text="{Binding Path=[weight]}" Grid.Column="5" FontSize="17" VerticalTextAlignment="Center"/>
                <BoxView HeightRequest="1" BackgroundColor="#BDBDBD" Grid.Row="1" Grid.ColumnSpan="6" Margin="-5,5,-5,0" VerticalOptions="End"/>
            </CustomGrid>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

To hide the columns with width = 0 I use a custom controller that inherits from Grid. The only thing this does is to override the OnSizeAllocated to set the HeightRequest to 0 if the width is 0 to completely hide the column, and set it to -1 to get the auto height back. Not sure if this is still needed, but it was in older versions of Xamarin forms. It also seems like setting the height back to -1 does not work as intended anymore. Implementation of the custom Grid:

 public class CustomGrid : Grid
    {
        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);

            foreach (View child in Children)
            {
                if (child.Width == 0 || child.Width < -1)
                    child.HeightRequest = 0;
                else
                    child.HeightRequest = -1;
            }
        }
    }

Problem:
With one or two columns it works just fine. With 5-6 columns the performance is not like it should be, even if half of the columns are hidden with width = 0. I guess they are included in the measurement of the layout anyway, so it doesn't really matter if they are visible or not(?). When assigning some items to the ItemSource, populating the Collectionview "lags". You can see each item beeing added one by one, while with fewer columns they all pop up at the same time without the lagging experience. I'm aware that using Height = Auto in a Grid is a performance hit, and if I change this part the performance is a lot better. But I still need to display all the information in the labels, which means that the height will vary, and I haven't found another good solution for this.

I see a lot of cool stuff with great performance arround the community, so I hope there is someone out there with some knowledge they would like to share about increasing the performance of this kind of layout. It will be greatly appreciated!

[Bug] Grid ColumnDefination & RowDefination

$
0
0

I am trying to change the width of the Column and height of the row programmatically. However I found out, whenever I change any of the Column or Row, the rest will follow. Is this a bug?

private void GenerateControl()
        {
            Grid grid = new Grid();

            var r = new RowDefinition();
            var c = new ColumnDefinition();
            for (int i = 0; i < 3; i++)
            {
                r.Height = 100;
                c.Width = 100;

                grid.ColumnDefinitions.Add(c);
                grid.RowDefinitions.Add(r);
            }

            TestLayout.Children.Clear();
            TestLayout.Children.Add(grid);
            foreach (var CD in grid.ColumnDefinitions)
            {
                Debug.WriteLine("Before - Col: " + CD.Width.ToString());
            }
            foreach (var CR in grid.RowDefinitions)
            {
                Debug.WriteLine("Before - Row " + CR.Height.ToString());
            }
            grid.ColumnDefinitions[0].Width = 50;
            grid.RowDefinitions[0].Height = 50;

            foreach (var CD in grid.ColumnDefinitions)
            {
                Debug.WriteLine("After - Col: " +CD.Width.ToString());
            }
            foreach (var CR in grid.RowDefinitions)
            {
                Debug.WriteLine("After - Row " + CR.Height.ToString());
            }
        }

Output:
[0:] Before - Col: 100.Absolute
[0:] Before - Col: 100.Absolute
[0:] Before - Col: 100.Absolute
[0:] Before - Row 100.Absolute
[0:] Before - Row 100.Absolute
[0:] Before - Row 100.Absolute
[0:] After - Col: 50.Absolute
[0:] After - Col: 50.Absolute
[0:] After - Col: 50.Absolute
[0:] After - Row 50.Absolute
[0:] After - Row 50.Absolute
[0:] After - Row 50.Absolute

Sqlite.Net db file not creating

$
0
0

In my project am using sqlite its working fine in debug mode when coming to release mode its not working. In release mode db file not creating.

    public static void GetDBFile(string dbPath, ISQLitePlatform sqlitePlatform)
    {
        if (dbUtils == null)
        {
            dbUtils = new DataAccess(sqlitePlatform, dbPath);
        }
    }

I written like this in App.xaml.cs file calling this method in Mainactivity.cs ( Android project )

        dbPath = FileAccessHelper.GetLocalFilePath("dbfilename.sqlite");
    App.GetDBFile(dbPath, new SQLitePlatformAndroidN());

Issue with SwipeView and Listview

$
0
0

I only want to display the TopItems (Swipe down) if my ListView is also on top position "1". I would like to implement my own "Pull to Refresh" functionality, but the function is also active when I just scroll up (by Swiping down).
Any Ideas ?

FontAwesome in iOS doesn't work

$
0
0

In my app, I put the fonts in the main project and export the fonts from the AssemblyInfo.cs like:

[assembly: ExportFont("FontAwesome5BrandsRegular.otf", Alias = "FontAwesomeBrands")]
[assembly: ExportFont("FontAwesome5Solid.otf", Alias = "FontAwesomeSolid")]
[assembly: ExportFont("FontAwesome5Regular.otf", Alias = "FontAwesomeRegular")]

[assembly: ExportFont("InterMedium.ttf", Alias = "InterMedium")]

All fonts are working. I'm facing an issue only with FontAwesome in iOS. What I see on the iOS app is:

but in Android is working fine.

How can I detect if a SwipeView is generally closing

$
0
0

I want so disable some of my controls while the SwipeView is open. So ein implemented an new Property "IsSwiping" and set it to True when the Event "SwipeStarted" fires. Now I have to reckognize if the SwipeView is closed. I tried the obvious Event "CloseRequested" but it is only Firing, when I programmatically close the SwipeView and not if I just tab on the screen.

Long story short: how can I detect if a SwipeView is generally closing ?


Is it possible to send notification on button click without using Firebase or third party in Forms?

$
0
0

Hi All,
I hope you all are well. I want to ask a question.
Is it possible to send notification on button click without using Firebase or a third party in Xamarin.Forms? I want to make service for notification. If anyone have any idea please suggest me.

Create ListView with two cards in each row.

$
0
0

Hello, i am new in xamarin forms. Is it possible to create a listview like image below?

Each row to contain two cards. Also i need to look the same in android and IOs

The return value is always false even the setter is true

$
0
0
namespace TravelRecord
{
    public class ValidatableObject<T> : ExtendedBindableObject, IValidity, INotifyPropertyChanged
    {

        public bool IsValid { get; set; }
        public T Value { get; set; }

    }
}

View Model

public class RegisterViewModel : BaseViewModel
{
    public ValidatableObject<string> FirstName { get; set; } 
}

View

<local:RoundedEntry Placeholder="First name" WidthRequest="100" Style="{StaticResource RoundedEntryStyle}"
                    Text="{Binding FirstName.Value }">
    <local:RoundedEntry.Behaviors>
        <local:EntryEmptyValidationBehaviour User="{Binding Source={x:Reference page}, Path=BindingContext.FirstName, Mode=TwoWay}" />
    </local:RoundedEntry.Behaviors>
</local:RoundedEntry>

Behavior

namespace TravelRecord
{
    public class EntryEmptyValidationBehaviour : BehaviorBase<RoundedEntry>
    {

        RoundedEntry control;
        string _placeHolder;
        Color _placeHolderColor;

        static ValidatableObject<string> user;

        public static readonly BindableProperty UserProperty =
        BindableProperty.Create(
        nameof(User),
        typeof(ValidatableObject<string>),
        typeof(EntryEmptyValidationBehaviour),
        null,
        BindingMode.TwoWay,
        propertyChanged: (bindableObject, oldValue, newValue) =>
        {
            user =  (ValidatableObject<string>)newValue;
        });
        public ValidatableObject<string> User {
            get => (ValidatableObject<string>)GetValue(UserProperty); 
            set => SetValue(UserProperty, value); 
        }

        protected override void OnAttachedTo(RoundedEntry bindable)
        {

            control = bindable;
            _placeHolder = bindable.Placeholder;
            _placeHolderColor = bindable.PlaceholderColor;
            bindable.TextChanged += OnEntryTextChanged;
        }

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

        void OnEntryTextChanged(object sender, TextChangedEventArgs e)
        {
            var control = (RoundedEntry)sender;
            var NotEmpty = !string.IsNullOrEmpty(e.NewTextValue);
            control.Placeholder = NotEmpty ? _placeHolder : "Required";
            control.PlaceholderColor = NotEmpty ? _placeHolderColor : Color.Red;
            user.IsValid = NotEmpty ? true : false;

        }

    }
}

How to set a diferent location of my current location?

$
0
0

I want to set a diferent location of my current location
I'm developing a ecommerce app With delivery and i want to my customers can choose the place or site for receipt her orders

When you have all your Order complete

Then you check your location and put your reference about your home and your house number
I save the Latitude and longitude of your current position, but I want to my customer can choose a diferent location
For example if you are in your work and you want to receipt your order in your home, you should choose a diferent location in the map

Please Help me

How to get back to app after google login

$
0
0

Hi Everyone,

I'm trying to implement google login in my app using xamarin.auth like below

var auth = new OAuth2Authenticator("284202576320-7kgdhaa5sgvkoe03jmmcv0p8lfdma306.apps.googleusercontent.com","cAZW7uegD-h2-
                                                             tNMMf5q1UGQ","https://www.googleapis.com/auth/userinfo.email",new 
                                                             Uri("https://accounts.google.com/o/oauth2/auth"),new 
                                                             Uri("http://dev.myfav.restaurant/Account/LoginComplete"),new 
                                                             Uri("https://accounts.google.com/o/oauth2/token"),null,true)
        {
            AllowCancel = true,                
        };

but Completed event not firing and its going to web page after login :( i need to get back user to my app how can i achieve this ???? Can anyone help me on this please.

Thanks in advance

Viewing all 89864 articles
Browse latest View live


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