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

Using FAB.forms ?

$
0
0

I am trying to add a Flating Action Button to a simple listview using FAB.forms but nothing is appearing & there are no build errors.

I have added FAB.forms v2.1.1 to a XAmarin Forms PCL project and also added Xamarin.Android.Support.Design to Android Packages.

Following the provided guides I have constructed my XAML page as follows

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:FABTest"
             xmlns:fab="clr-namespace:FAB.Forms;assembly=FAB.Forms"
             x:Class="FABTest.Contacts" >
  <ContentPage.Content>
        <RelativeLayout>
            <ContentView
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=10}"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=10}">
    <ListView x:Name="EndpointListView" ItemsSource="{Binding Items}" IsVisible="{Binding IsListVisible}" HasUnevenRows="True" SeparatorColor="{DynamicResource ListViewSeparatorColor}" >
      <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding Name}" />
            </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </ContentView>
            <fab:FloatingActionButton
                x:Name="fabBtn"
                Source="plus.png"
                Size="Normal"
                Clicked="Handle_FabClicked"
                NormalColor="Green"
                RippleColor="Red"
                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=-50}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=-50}" />
        </RelativeLayout>
    </ContentPage.Content>
</ContentPage>

Are there other additional packages I should be using to get this working?


DropTableAsync not working as intended?

$
0
0

I seem to be unable to drop my table using DropTableAsync:

public Task<int> dropTable()
        {
            return db.DropTableAsync<Foundation>();
        }

And invoked here:

protected override async void OnAppearing()
        {
            base.OnAppearing();
            var i = await App.Database.dropTable();
            var result = await App.Database.GetItemsAsync();
            ListView lv = lvResults;
            // Reset the 'resume' id, since we just want to re-start here
            lvResults.ItemsSource = result;
        }

I've tried stepping through the code with breakpoints, but as soon as App.Database.dropTable() gets invoked I get an AggregateException:

System.AggregateException: One or more errors occurred.

As with all my previous questions regarding SQLite NET I'm following Xamarin's guide on working with local databases and their Todo repo.

Button image does not appear in UWP app

$
0
0

Hi,
My app's XAML:
<?xml version="1.0" encoding="utf-8" ?>

  <Button Image="clock.png"/>

</ContentPage>

The code above isn't correct, because when I paste it into the forum, it get's cut. That's why you don't see ContentPage opening - it's there in my app. The importnat thing to know is that I have just one button with an image - and that's it.

It's very simple xaml and it works well on Android. Unfortunately it doesn't work in UWP.
In case of Android I put clock.png into Resources/drawable.
In case of UWP I put clock.png into project's root folder, just like described here:https://developer.xamarin.com/guides/xamarin-forms/working-with/images/

Unfortunately, UWP app has a button without any content. What's wrong?

UWP - get filepath of content file in package

$
0
0

Has anyone any idea why this should behave erratically (by erratic I mean - under debugger emulator or desktop or win10 device, the processing simply hangs sometimes and not others. It is often cleared by eithe a) cleaning and full rebuild, closing emulator, restarting phone device. the file is marked as 'content' copy always. Also sometimes it will return correctly if one steps through line by line with debugger - often works first time this is called in code then fails next time)

var fileToRead = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ngar.db3"));

(PS yes I know I should be doing this asynchronously but its a pastiche of old code and not doing it synchronously would mean quite a bit of reconstruction elsewhere)

any suggestions appreciated
J

Where are forms??

$
0
0

Hi, today I can't add new Forms in my project... I try to add new Element but there isn't xamarin forms... Why?!?

Set Toolbaritem icon

$
0
0

Hi,

I'm trying to set the icon of a toolbar item.
I have a forms solution with a project for Android and one for iOS.

As the icon attribute expects a FileImageSource I'm not able to simply set it to an ImageSource.
The documentation is guessing to load it by simply setting
TollbarItem.Icon = "icon.png" but this is definitely not working.

In Android I stored the icon in the drawable folder and it's working fine. The image is loaded. But the problem comes with the iOS version!

In iOS I usually use the XCassets catalog and I don't see why I shouldn't especially as it is the default way in iOS development to manage images.
The Xamarin documentation mentions to copy the image in to the root folder of the project, what doesn't feel like a justifiable solution for me, but even if I do that it's not working!
I also tried to set it like ToolbarItem.Icon = "Images.xcassets/icon.imageset/icon.png"; but this, too, isn't working.

I assume I start from the Resources folder to load the image from. I tried for a whole day now but nothing works.
That's my code for that part (as said, working in Android)

string icon  = "Images.xcassets/icon.imageset/icon.png";
if(Device.OS == TargetPlatform.Android)
    icon = "icon.png";
if (Device.OS == TargetPlatform.Android || Device.OS == TargetPlatform.iOS)
    RegistrationButton.Icon = icon;

So, how can one set the icon of a ToolbarItem in iOS?

Thanks.

Best regards

GetItemsAsync function suddenly isn't invoked.

$
0
0
    Suddenly my GetItemsAsync (based strictly on Xamarin's guide on working with local databases).

protected override async void OnAppearing()
            {
                base.OnAppearing();
                var result = await App.Database.GetItemsAsync(); //HERE
                ListView lv = lvResults;
                Debug.WriteLine("Count: " + result.Count());
                // Reset the 'resume' id, since we just want to re-start here
                lvResults.ItemsSource = result;
            }

Using breakpoints the function call doesn't enter the GetItemsAsync (it DOES exist and intelli-J picks it up):

        public Task<List<Foundation>> GetItemsAsync(int id)
        {
            var rows = db.Table<Foundation>().CountAsync();
            Debug.WriteLine("Rows: " + rows.Result);
            return db.Table<Foundation>().Where(i => i.ID == id).ToListAsync();

        }

The breakpoint on var rows ... isn't getting picked up, but no error is thrown. I'm assuming this means that the function body never gets used?
I'm trying to troubleshoot my sodden database, since it simply doesn't seem to want to return any data (even though it really shoud...).

At the moment I'm really pulling my hair out because it seems like it should work... T_T

Remove listview selection background colour.

$
0
0

Hi, how to remove iOS listview selection background colour? Thanks in advance.


App resuming results in crash with FormsAppCompatActivity

$
0
0

I have a Xamarin Forms app, currently being built for Android. I have a MainActivity that used to extend FormsApplicationActivity, but because I want to use a custom theme I had to change it to extend FormsAppCompatActivity (see my other question: http://stackoverflow.com/questions/35754590/xamarin-forms-custom-theme-not-working).

Ever since changing from FormsApplicationActivity to FormsAppCompatActivity the app crashes whenever I switch out of the app and then back into the app. It throws an error in the App.xaml.cs class in the OnResume method, where I try to set the MainPage to a new navigation page:

protected override void OnResume()
{
    bool isRegistered = _authenticationService.IsRegistered();

    MainPage = isRegistered
        ? new NavigationPage(new LoginPage())
        : new NavigationPage(new RegisterPage()); // this results in the crash
}

The error I'm getting is:

Java.Lang.IllegalStateException: Can not perform this action after
onSaveInstanceState

This is the stacktrace:

03-09 13:43:52.098 I/MonoDroid( 1243): Java.Lang.IllegalStateException: Can not perform this action after onSaveInstanceState
03-09 13:43:52.098 I/MonoDroid( 1243):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
03-09 13:43:52.098 I/MonoDroid( 1243):   at Android.Runtime.JNIEnv.CallIntMethod (IntPtr jobject, IntPtr jmethod) [0x00063] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:386
03-09 13:43:52.098 I/MonoDroid( 1243):   at Android.Support.V4.App.FragmentTransactionInvoker.Commit () [0x00033] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.SwitchContentAsync (Xamarin.Forms.Page view, Boolean animated, Boolean removed, Boolean popToRoot) [0x000e1] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnPushAsync (Xamarin.Forms.Page view, Boolean animated) [0x00000] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.PushViewAsync (Xamarin.Forms.Page page, Boolean animated) [0x00000] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.<OnElementChanged>b__13_0 (Xamarin.Forms.Page p) [0x00000] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.EnumerableExtensions.ForEach[T] (IEnumerable`1 enumeration, System.Action`1 action) [0x00010] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1 e) [0x001af] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x000fc] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, Boolean layout) [0x00015] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00090] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0001a] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.AppOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x0001e] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00012] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Application.set_MainPage (Xamarin.Forms.Page value) [0x0008b] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Smartbit.App.OnResume () [0x00020] in C:\Users\leonc\Documents\Visual Studio 2015\Projects\Smartbit\Smartbit\Smartbit\App.xaml.cs:52
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Application.SendResume () [0x00006] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnStateChanged () [0x00039] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnRestart () [0x00019] in <filename unknown>:0
03-09 13:43:52.098 I/MonoDroid( 1243):   at Android.App.Activity.n_OnRestart (IntPtr jnienv, IntPtr native__this) [0x00009] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:4539
03-09 13:43:52.098 I/MonoDroid( 1243):   at (wrapper dynamic-method) System.Object:cba7a870-1435-4f70-9059-e10915aba0c0 (intptr,intptr)
03-09 13:43:52.098 I/MonoDroid( 1243):   --- End of managed exception stack trace ---
03-09 13:43:52.098 I/MonoDroid( 1243): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1448)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1466)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:634)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:613)
03-09 13:43:52.098 I/MonoDroid( 1243):  at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onRestart(Native Method)
03-09 13:43:52.098 I/MonoDroid( 1243):  at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onRestart(FormsAppCompatActivity.java:86)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.app.Instrumentation.callActivityOnRestart(Instrumentation.java:1181)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.app.Activity.performRestart(Activity.java:5291)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.app.Activity.performResume(Activity.java:5302)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2764)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2803)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.os.Handler.dispatchMessage(Handler.java:102)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.os.Looper.loop(Looper.java:136)
03-09 13:43:52.098 I/MonoDroid( 1243):  at android.app.ActivityThread.main(ActivityThread.java:5001)
03-09 13:43:52.098 I/MonoDroid( 1243):  at java.lang.reflect.Method.invokeNative(Native Method)
03-09 13:43:52.098 I/MonoDroid( 1243):  at java.lang.reflect.Method.invoke(Method.java:515)
03-09 13:43:52.098 I/MonoDroid( 1243):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-09 13:43:52.098 I/MonoDroid( 1243):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-09 13:43:52.098 I/MonoDroid( 1243):  at dalvik.system.NativeStart.main(Native Method)

FireBase Messaging is not yet resolved

$
0
0

Dear Xamarin lovers. I am unable to install the Xamarin.Firebase.Messaging version 42.1001.0-beta2 in xamarin forms.
please resolve this error and help to me 1. * 1. * #
Severity Cod Description Project File Line Suppression State Error
Unable to find a version of 'Xamarin.GooglePlayServices.Basement' that is compatible with 'Xamarin.Firebase.Common 42.1001.0-beta2 constraint: Xamarin.GooglePlayServices.Basement (= 42.1001.0-beta2)', 'Xamarin.Firebase.Iid 42.1001.0-beta2 constraint: Xamarin.GooglePlayServices.Basement (= 42.1001.0-beta2)', 'Xamarin.Firebase.Messaging 42.1001.0-beta2 constraint: Xamarin.GooglePlayServices.Basement (= 42.1001.0-beta2)', 'Xamarin.GooglePlayServices.Base 29.0.0.2-beta1 constraint: Xamarin.GooglePlayServices.Basement (= 29.0.0.2-beta1)', 'Xamarin.GooglePlayServices.Gcm 29.0.0.2-beta1 constraint: Xamarin.GooglePlayServices.Basement (= 29.0.0.2-beta1)', 'Xamarin.GooglePlayServices.Iid 42.1001.0-beta2 constraint: Xamarin.GooglePlayServices.Basement (= 42.1001.0-beta2)', 'Xamarin.GooglePlayServices.Measurement 29.0.0.2-beta1 constraint: Xamarin.GooglePlayServices.Basement (= 29.0.0.2-beta1)', 'Xamarin.GooglePlayServices.Tasks 42.1001.0-beta2 constraint: Xamarin.GooglePlayServices.Basement (= 42.1001.0-beta2)'.

i am tried from github firebase samples also. but its taking 1 month time a go but not resolved please help me to resolve this error as soon as possible
and one more request xamarin forums also no one cannot give solution for fire base messaging

Xamarin.Forms - IOS build with the last update

$
0
0

Hello!

I have a simple application that uses Xamarin Forms 2.3.3.175.
Yesterday, I have updated my Visual Studio 2015 with the last Xamarin update (4.2.1.73), Xamarin.iOS 10.3.0.0 and I also updated the mac with the last Xamarin Studio (6.1.2) -and Xamarin.iOS 10.3.0.0.

Before the update, the project's build was ok, but now I'm trying to build and an error appears:

Your application is using the 'Speech' framework, which isn't included in the iOS SDK you're using to build your app (this framework was introduced in iOS 10.0.0, while you're building with the iOS 10.0 SDK.) This configuration is only supported with the legacy registrar (pass --registrar:legacy as an additional mtouch argument in your project's iOS Build option to select). Alternatively select a newer SDK in your app's iOS Build options.

I tryed to use this monotouch parameter "--registrar", but it doesn't work...
And I'm not using the 'Speech' framework...

Someone of you have any information about this?

Thanks!

Custom emoji keyboard for crossplatform

$
0
0

Hello,

Im working in chat project what needs a set of my own emoticons.
But I couldn't find the way to implement emoji keyboard for cross platform, anyone can help me?

Thanks a lot.

Bottom Tabs for Xamarin.Android (in Xamarin.forms app)

$
0
0

I'm making app with using Xamarin.forms.

You all know regular tabs for Android from Xamarin.forms' TabbedPage is at top. Because it should be there if it's Native Android app that respect Android UX.

But things are changed now. Even Google announced new bottom tab bar called "bottom Navigation".
https://github.com/roughike/BottomBar
And many major apps are using bottom tab bar.

But I can't use new Bottom Navigation. Because my app is base on Xamarin.forms and uses TabbedPage from forms. It's going to be more complicated if I try to use bottom Navigation.

(I'm making iOS app from forms too)

So Best approach would be moving native Tabs to bottom.

So I found this. (maybe old)
http://envyandroid.com/align-tabhost-at-bottom/

But don't know how to use in Xamarin.Android. Could you help me?

Not Work Command or GestureRecognize in platfomr ios

$
0
0

hello, I implemented and modified the swipe view dle segunte link:
matchboxmobile.com/blog/xamarin-forms-swipecard-tutorial/
But everything works on Android, while on ios does not recognize the clicks.
Things might be?

The following is my code:
My Xaml:

 <ContentView.Content>
    <StackLayout BackgroundColor="White" InputTransparent="True">
      <StackLayout  Orientation="Horizontal" HorizontalOptions="FillAndExpand">
        <Label x:Name="_Name" FontSize="22" Margin="10,5,10,5" TextColor="{StaticResource primaryColor}"
               HorizontalTextAlignment="Center" InputTransparent="True"></Label>
        <iconize:IconImage  Margin="10,5,10,5" x:Name="favoriteButton"  HeightRequest="30" HorizontalOptions="EndAndExpand"  WidthRequest="30"  IconColor="Red" />

      </StackLayout>
      <Image  x:Name="_Photo" Aspect="AspectFill"  InputTransparent="True">
           <Image.HeightRequest>
               <OnPlatform x:TypeArguments="x:Double"
                    iOS="200"
                    Android="200"/>
           </Image.HeightRequest>
      </Image>
      <Label x:Name="_Description" FontSize="18" TextColor="Gray"
             HorizontalTextAlignment="Center"  HorizontalOptions="CenterAndExpand"
             InputTransparent="True"></Label>
      <StackLayout VerticalOptions="EndAndExpand">
          <customControl1:RoundedButton TypeButton ="Primary" Text="Contatta" Command="{Binding contactUser}"/>
      </StackLayout>
      <BoxView Margin="10,0,10,0" HeightRequest="1" HorizontalOptions="Fill" BackgroundColor="Gray" VerticalOptions="End"/>
      <StackLayout VerticalOptions="End" HorizontalOptions="Center" Orientation="Horizontal" Margin="10">
        <Label x:Name="_CurrentItem" FontSize="12" TextColor="Gray" HorizontalTextAlignment="Center" InputTransparent="True"></Label>
        <Label Text="di" TextColor="Gray" FontSize="12" HorizontalTextAlignment="Center" InputTransparent="True"></Label>
        <Label x:Name="_TotalItems" FontSize="12"  TextColor="Gray" HorizontalTextAlignment="Center" InputTransparent="True"></Label>
      </StackLayout>
    </StackLayout>
  </ContentView.Content>

My xaml.cs:

  public partial class CardViewCust : ContentView
    {
        public Label Name { get; set; }
        public Image Photo { get; set; }
        //   public Label Location { get; set; }
        public Label Description { get; set; }
        public Label CurrentItem { get; set; }
        public Label TotalItems { get; set; }
        public CardViewCust()
        {
            InitializeComponent();
            Name = _Name;
            Photo = _Photo;
            //Location = _Location;
            Description = _Description;
            CurrentItem = _CurrentItem;
            TotalItems = _TotalItems;
            favoriteButton.Icon = "fa-heart-o";

            favoriteButton.GestureRecognizers.Add(new TapGestureRecognizer(OnTap));
         //   _Photo.GestureRecognizers.Add(new TapGestureRecognizer(OnTap));


            var tapGestureRecognizer = new TapGestureRecognizer();
            tapGestureRecognizer.SetBinding(TapGestureRecognizer.CommandProperty, "tap");
            _Photo.GestureRecognizers.Add(tapGestureRecognizer);
        }

        private void OnTap(View view, object o)
        {
            favoriteButton.RotateXTo(360);
            favoriteButton.Icon = "fa-heart";

        }
    }
}

My CardViewStack:

  public class CardStackView : ContentView
    {
        public class Item
        {
            public int Index { get; set; }
            public string Name { get; set; }

            public string Photo { get; set;}
            public string Location { get; set;}
            public string Description { get; set;}
        };


        // back card scale
        const float BackCardScale = 0.8f;
        // speed of the animations
        const int AnimLength = 250;
            // 180 / pi
        const float DegreesToRadians = 57.2957795f;
        // higher the number less the rotation effect
        const float CardRotationAdjuster = 0.3f;
        // distance a card must be moved to consider to be swiped off
        public int CardMoveDistance {get; set;}

        // two cards
        const int NumCards = 2;
        public CardViewCust[] cards = new CardViewCust[NumCards];
        // the card at the top of the stack
        int topCardIndex;
        // distance the card has been moved
        float cardDistance = 0;
        // the last items index added to the stack of the cards
        int itemIndex = 0;
        bool ignoreTouch = false;

        // called when a card is swiped left/right with the card index in the ItemSource
        public Action<int> SwipedRight = null;
        public Action<int> SwipedLeft = null;

        public static readonly BindableProperty ItemsSourceProperty =
            BindableProperty.Create(nameof(ItemsSource), typeof(System.Collections.IList), typeof(CardStackView), null,
            propertyChanged: OnItemsSourcePropertyChanged);

        public List<Item> ItemsSource {
            get {
                return (List<Item>)GetValue (ItemsSourceProperty);
            }
            set {
                SetValue (ItemsSourceProperty, value);
                itemIndex = 0;
            }
        }

        private static void OnItemsSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            ((CardStackView)bindable).Setup();
        }

        public CardStackView ()
        {
            RelativeLayout view = new RelativeLayout ();

            // create a stack of cards
            for (var i = 0; i < NumCards; i++) {
                var card = new CardViewCust();
                cards[i] = card;
                card.InputTransparent = true;
                card.IsVisible = false;

                view.Children.Add(
                    card,
                    Constraint.Constant(0),
                    Constraint.Constant(0),
                    Constraint.RelativeToParent((parent) => parent.Width),
                    Constraint.RelativeToParent((parent) => parent.Height)
                );
            }

            this.BackgroundColor = Color.Black;
            this.Content = view;

            var panGesture = new PanGestureRecognizer ();
            panGesture.PanUpdated += OnPanUpdated;
            GestureRecognizers.Add (panGesture);

        }

        void Setup()
        {
            // set the top card
            topCardIndex = 0;
            // create a stack of cards
            var j = Math.Min(NumCards, ItemsSource.Count);

            for (int i = 0; i < Math.Min(NumCards, ItemsSource.Count); i++) {
                if (itemIndex >= ItemsSource.Count)
                {
                    itemIndex = 0;
                    //break;
                }
                var card = cards[i];
                card.Name.Text = ItemsSource[itemIndex].Name;
                //  card.Location.Text = ItemsSource[itemIndex].Location;
                card.Description.Text = ItemsSource[itemIndex].Description;
                card.CurrentItem.Text = ItemsSource[itemIndex].Index.ToString();
                card.TotalItems.Text = ItemsSource.Count.ToString();
                card.Photo.Source = ImageSource.FromFile(ItemsSource[itemIndex].Photo);
                card.IsVisible = true;
                card.Scale = GetScale(i);
                card.RotateTo (0, 0);
                card.TranslateTo (0, - card.Y, 0);
                ((RelativeLayout)this.Content).LowerChild (card);
                itemIndex++;
            }
        }

        void OnPanUpdated (object sender, PanUpdatedEventArgs e)
        {
            switch (e.StatusType) {
                case GestureStatus.Started:
                    HandleTouchStart();
                    break;
                case GestureStatus.Running:
                    HandleTouch((float)e.TotalX);
                    break;
                case GestureStatus.Completed:
                    HandleTouchEnd();
                    break;
            }
        }

        // to hande when a touch event begins
        public void HandleTouchStart()
        {
            cardDistance = 0;
        }

        // to handle te ongoing touch event as the card is moved
        public void HandleTouch(float diff_x)
        {
            if (ignoreTouch) {
                return;
            }

            var topCard = cards [topCardIndex];
            var backCard = cards [PrevCardIndex (topCardIndex)];

            // move the top card
            if (topCard.IsVisible) {

                // move the card
                topCard.TranslationX = (diff_x);

                // calculate a angle for the card
                float rotationAngel = (float)(CardRotationAdjuster * Math.Min (diff_x / this.Width, 1.0f));
                topCard.Rotation = rotationAngel * DegreesToRadians;

                // keep a record of how far its moved
                cardDistance = diff_x;
            }

            // scale the backcard
            if (backCard.IsVisible) {
                backCard.Scale = Math.Min (BackCardScale + Math.Abs ((cardDistance / CardMoveDistance) * (1.0f - BackCardScale)), 1.0f);
            }
        }

        // to handle the end of the touch event
        public async void HandleTouchEnd()
        {
            ignoreTouch = true;

            var topCard = cards [topCardIndex];

            // if the card was move enough to be considered swiped off
            if (Math.Abs ((int)cardDistance) > CardMoveDistance) {

                // move off the screen
                await topCard.TranslateTo (cardDistance>0?this.Width:-this.Width, 0, AnimLength/2, Easing.SpringOut);
                topCard.IsVisible = false;

                if (SwipedRight != null && cardDistance > 0) {
                    SwipedRight(itemIndex);
                }
                else
                {
                    SwipedLeft?.Invoke(itemIndex);
                }

                // show the next card
                ShowNextCard ();

            }
            // put the card back in the center
            else {

                // move the top card back to the center
                topCard.TranslateTo ((-topCard.X), - topCard.Y, AnimLength, Easing.SpringOut);
                topCard.RotateTo (0, AnimLength, Easing.SpringOut);

                // scale the back card down
                var prevCard = cards [PrevCardIndex (topCardIndex)];
                await prevCard.ScaleTo(BackCardScale, AnimLength, Easing.SpringOut);

            }

            ignoreTouch = false;
        }

        // show the next card
        void ShowNextCard()
        {
            if (cards[0].IsVisible == false && cards[1].IsVisible == false) {
                Setup();
                return;
            }

            var topCard = cards [topCardIndex];
            topCardIndex = NextCardIndex (topCardIndex);

            // if there are more cards to show, show the next card in to place of
            // the card that was swipped off the screen
            if (itemIndex < ItemsSource.Count) {
                // push it to the back z order
                ((RelativeLayout)this.Content).LowerChild(topCard);

                // reset its scale, opacity and rotation
                topCard.Scale = BackCardScale;
                topCard.RotateTo(0, 0);
                topCard.TranslateTo(0, -topCard.Y, 0);

                // set the data
                topCard.Name.Text = ItemsSource[itemIndex].Name;
            //  topCard.Location.Text = ItemsSource[itemIndex].Location;
                topCard.Description.Text = ItemsSource[itemIndex].Description;
                topCard.CurrentItem.Text = ItemsSource[itemIndex].Index.ToString();
                topCard.TotalItems.Text = ItemsSource.Count.ToString();

                topCard.Photo.Source = ImageSource.FromFile(ItemsSource[itemIndex].Photo);

                topCard.IsVisible = true;
                itemIndex++;
            }
        }

        // return the next card index from the top
        int NextCardIndex(int topIndex)
        {
            return topIndex == 0 ? 1 : 0;
        }

        // return the prev card index from the yop
        int PrevCardIndex(int topIndex)
        {
            return topIndex == 0 ? 1 : 0;
        }

        // helper to get the scale based on the card index position relative to the top card
        float GetScale(int index)
        {
            return (index == topCardIndex) ? 1.0f : BackCardScale;
        }
    }

Can I develop for Windows Phone with the new Visual Studio for Mac


Unknown option '--no-version-vectors--no-version-vectors'

$
0
0

I have a Xamarin.Forms project that started to show the error Unknown option '--no-version-vectors--no-version-vectors' when trying to build the android app. Tried reinstall Xamarin and android SDK but the error still happen. Also tried to add <AndroidSdkBuildToolsVersion>20.0.0</AndroidSdkBuildToolsVersion> to the project file but nothing changes. Any hint on what is happening?

Why does ContentPage.Appearing called twice?

$
0
0

I have a TabbedPage and 2 Content Pages as child of the TabbedPage.

  <TabbedPage.Children>
    <ContentPage x:Name="Page1">
    </ContentPage>
    <ContentPage x:Name="Page2">
    </ContentPage>
  </TabbedPage.Children>



Page1.Appearing += Page1_Appearing;
Page2.Appearing += Page2_Appearing;

When I set

App.Current.MainPage = new MyTabbedPage();

The Appearing event gets fired twice and so the Page1_Appearing.

Is there a way to prevent this?

PS: The contstructor of the TabbedPage is called once.

WebView performance issues while webPage Loading..

$
0
0

Hello,
I'm trying to load one webpage in WebView but the loading of webpage is so slow, how can i and we improve WebView performance in app ?
is there any alternative way to load webpages like WebView?

LongPress listView Xamarin Forms

$
0
0

Hello Everyone.

I have previously consulted about MR.Gestures. I followed the example of the following site:

http://www.mrgestures.com/

But when I run my code I do not perform the event, someone can tell me how to solve or implement the event, here is the simple code of my test

XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mr="clr-namespace:MR.Gestures;assembly=MR.Gestures"
             x:Class="PressLong.xaml"
             Title="Xaml">
  <StackLayout HorizontalOptions="Center">
    <mr:BoxView x:Name ="box"
                Color="#33ff4b"
                WidthRequest="150"/>
  </StackLayout>
</ContentPage>

CS

using Xamarin.Forms;

namespace PressLong
{
    public partial class xaml : ContentPage
    {
        public xaml()
        {
            InitializeComponent();
            box.LongPressing += Box_LongPressing;
        }

        private void Box_LongPressing(object sender, MR.Gestures.LongPressEventArgs e)
        {
            DisplayAlert("Example",e.Duration.ToString(),"OK");
        }
    }
}

How to set Button text without changes (not in uppercase)?

$
0
0

Hello,

I have this xaml for button:

<Button Text="Click here!" Image="icon.png" ContentLayout="Top, 0"/>

But the text is displayed in uppercase and I want it without changes. Is it posible?

Viewing all 91519 articles
Browse latest View live


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