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

Problems using ListView with SwipeView overlapping rows

$
0
0

Hi

I am trying to slide the ListView item to the left to access the Delete button.
When I slide the second line after the first, the first line does not return to the original position and
when I slide the other lines to the left, ONLY the last line is shown correctly, in the lines above the lines are superimposed.

See image

See xaml code

                   <ListView.ItemTemplate >
                        <DataTemplate >
                            <ViewCell >
                                    <SwipeView>
                                        <SwipeView.RightItems>
                                            <SwipeItems Mode="Reveal" >
                                                <SwipeItem Text="Excluir"          
                                                           CommandParameter="{Binding Source={x:Reference Item}, Path=BindingContext}"
                                                           BackgroundColor="Red" 
                                                           IconImageSource="delete.png"
                                                           Invoked ="IB_Invoked">
                                                </SwipeItem>
                                            </SwipeItems>
                                        </SwipeView.RightItems>

                                        <!-- conteudo do swipe view-->
                                        <Frame CornerRadius="20" Margin="1,1,1,1" HasShadow="True"  BorderColor="DarkBlue">
                                            <Grid x:Name="Item">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="40"/>
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="50"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="60"/>
                                                    <ColumnDefinition Width="90"/>
                                                </Grid.ColumnDefinitions>

                                                <Grid BackgroundColor="Blue">
                                                    <Label Grid.Row="0" Grid.Column="0" Text="{Binding QTY}"  Font="20" VerticalOptions="Center" HorizontalTextAlignment="Center" TextColor="White" />
                                                </Grid>
                                                <StackLayout Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                                                    <Label Text="{Binding DESCRIPTION}" VerticalTextAlignment="Center" Font="14" TextColor="Black" />
                                                </StackLayout>
                                                <StackLayout Grid.Row="0" Grid.Column="2" Orientation="Horizontal" HorizontalOptions="End">
                                                    <Label Text="{Binding TOTAL, StringFormat='{0:N2}'}" VerticalTextAlignment="Center" Font="14" TextColor="Black" />
                                                </StackLayout>
                                            </Grid>
                                        </Frame>
                                    </SwipeView>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>

Using custom font in Xamarin adds extra spacing below and above the text

$
0
0

Hello

I would like to use custom ( imported ttf ) font in Xamarin. I use Xamarin.Forms 4.4, I put ttf into Assets folder of my android project.
But when I display some text with this font, text is displayed with extra spacing above and below text ( red bordered areas on pic)

The VerticalTextAlignment works fine, but I don't know what are these spaces ( I guess these spaces are gaps between top and ascent values of font , and bottom and descent values of font) and how can I remove them? I tried set font metrics with fontforge (on Element -> Font info->OS/2->Metrics pane) but no effect.

I tried other ttf font, that font has extra spacing too, but size of spacing above and below text was different.

Xaml for upper Sample text:
<Label Text="Sample text" FontFamily="font.ttf#font name" FontSize="26" LineHeight="12" FontAttributes="Bold" VerticalOptions="End" VerticalTextAlignment="Start" BackgroundColor="Aqua" Padding="0" Margin="0" HeightRequest="100"/>

Xaml for other Sample text:
<Label Text="Sample text" FontFamily="font.ttf#font name" FontSize="26" LineHeight="12" FontAttributes="Bold" VerticalOptions="End" VerticalTextAlignment="Start" BackgroundColor="Aqua" Padding="0" Margin="0"/>

Thanks for your help

Binding not working

$
0
0

Hi, I have been trying to get a binding to work so that the back button is disabled once it has been clicked on. This is all done in MyContentPage which is inherited by all the pages within the App. There is not command on the button so that shouldn't be interfering with my binding.

Button to be enabled/unenabled:

        Button testButton = new Button()
                {
                    Text = "Test"
                };

                testButton.Clicked += TestButton_Clicked;
        testButton.BindingContext = this;
                testButton.SetBinding(Button.IsEnabledProperty, nameof(BackButtonEnabled));
    private void TestButton_Clicked(object sender, EventArgs e)
        {
            this.BackButtonEnabled = false;
        }

Property and property changed code:

        private bool _backButtonEnabled = true;
        /// <summary>
        /// Allows us to disable the back button when it is clicked so that we don't click on it multiple times.
        /// </summary>
        public bool BackButtonEnabled
        {
            get { return _backButtonEnabled; }
            set
            {
                if (value != _backButtonEnabled)
                {
                    _backButtonEnabled = value;
                    OnPropertyChanged(nameof(BackButtonEnabled));
                }
            }
        }

        protected override void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

I have also done the SetBinding() with a converter. The converter triggers when the bind is set but not when the Property Changed event has been triggered. All the this keywords appear to be picking up the Settings page (that inherits this class). It is pretty much exactly like another binding I have elsewhere in the App so I don't understand what I am doing wrong - can anybody else spot anything?

Thanks

Image from URL in MenuItem

$
0
0

Hello,
I just started developing Xamarin mobile apps.

I have one challenge that I cannot get around at the moment.

I planned to use AppShell to implement navigation. In my flyout header I placed an image with a URL to the image:

    <Image Aspect="AspectFit" 
           Source="https://xxxx.com/api/App/Download?fileId=5eb2a0a7e6865ba3c8c7ae32" 
           Opacity="0.9" />

That works great.

In my menu I need to show a list of menu items which is dynamic (for example companies) and I want to place an icon in front of it in the menuitem (the logo).

Unfortunately the MenuItem element is not accepting image sources from an url.

        this.Items.Add(new MenuItem() {  IconImageSource= "https://anyurl.com", Text = "Test", Command = ExecuteClientList, CommandParameter = "12" });

This does not work.

Is there a work around for that? Or is there another element instead of MenuItem to use instead?

Thanks in advance.

i want to know which other apps are running while my app is open on various Platforms??

$
0
0

Namaste Friends!!

i want to know what to do for this. i want to track my client actually. i want to know what client is running other apps while using my app and if a browser is open then i want to track at which site my user is surfing. don't take me wrong this is not public app its for my employees.. i want this app for various platforms that's why using xamarin forms.

Is there a way of getting all the used NuGet packages in a Xamarin.Forms project from the code?

$
0
0

Title...

I need to show all of the NuGet packages used in my app in the legal info. Is there a way of doing it programmatically so that I don't have to come back each time we use a new NuGet package?

Add menu item dynamically

$
0
0

Hello All,
My app has requirement that App menu items should show if the user is authorised to see otherwise only default item menu should see.
I am using AppShell Flyout for creating menu, so i need to add menu item dynamically also i need to do it by MVVM approach.. please help me to achieve this functionality.

Create Spinner Time picker on Xamari forms Android

$
0
0

My question is simple. Is there any way to create

Something like that instead of this ugly picker on android, and keep default one on IOS


iOS "Files" app, Android ExternalStorageDirectory and saving files

$
0
0

Hello,

Trying to rephrase a question I've asked before.

I'd like to save a generated .pdf file into a common folder on a device so that a user can find those files from say email app for an attachment or just view the file external to my app.

On my iOS device, I can open Files app and browser to various folders. I noticed some apps have their own folders under "On my phone" and I can manually create a folder there too.

I'd like my app to create it's own public folder on the device and save pdf files into that. The user can then view those files by simply navigating to that folder using the Files app without needing to use my app.

Found these two links - files in iOS
and this BlogPost for Android

Can anyone else advise?
As there a plugin or sample code that'll help?

I'm expecting to write a dependency service for this on each platform.

Thanks

Xamarin.forms 4.6 with indicator view?

$
0
0

The class, property, or method you are attempting to use ('.ctor') is part of IndicatorView; to use it, you must opt-in by calling Forms.SetFlags("IndicatorView_Experimental") before calling Forms.Init().

I am using Xamarin.Forms 4.6 and here is the code:
<IndicatorView IndicatorColor="#75FFFFFF" SelectedIndicatorColor="#FFFFFF" HorizontalOptions="Center" IndicatorSize="5.33" IndicatorsShape="Circle"></IndicatorView>

I added the SetFlags bu it not work.

Firebase app giving 'default firebaseapp is not initialized in this process' error

$
0
0

Hello guys.
I have an app that I am developing and that has been working fine for a long time now and the other day I tried to modify it to upload an update and I started gettting this error:

**Java.Lang.IllegalStateException:** 'Default FirebaseApp is not initialized in this process XXXXX. Make sure to call FirebaseApp.initializeApp(Context) first.'

I get the error when I run the app.

This is my MainActivity.cs

[Activity(Label = "XXXXX", Icon = "@mipmap/icon", MainLauncher = true, Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
#if DEBUG
            Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);
#endif
            base.OnCreate(savedInstanceState);

            Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            XF.Material.Droid.Material.Init(this, savedInstanceState);

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                var mChannel = new NotificationChannel("XXXXX", "XXXXX", NotificationImportance.Default);
                mChannel.Description = "Notificaciones de la APP";
                AudioAttributes audioAttributes = new AudioAttributes.Builder().SetContentType(AudioContentType.Sonification).SetUsage(AudioUsageKind.Notification).Build();
                Android.Net.Uri sound1 = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                mChannel.SetSound(sound1, audioAttributes);
                mChannel.EnableVibration(true);
                mChannel.SetVibrationPattern(new long[] { 800 });
                mChannel.ShouldVibrate();
                mChannel.EnableLights(true);
                mChannel.ShouldShowLights();
                var notificationManager = GetSystemService(NotificationService) as NotificationManager;
                notificationManager.CreateNotificationChannel(mChannel);

                FirebasePushNotificationManager.DefaultNotificationChannelId = "XXXXX";
                FirebasePushNotificationManager.DefaultNotificationChannelName = "XXXXX";
            }


            FirebasePushNotificationManager.IconResource = Resource.Drawable.firebase1;


            Android.Net.Uri sound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            FirebasePushNotificationManager.SoundUri = sound;

#if DEBUG
            FirebasePushNotificationManager.Initialize(this, true, false);

#else
            FirebasePushNotificationManager.Initialize(this, false, false);
#endif

            LoadApplication(new App());



            Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

            Window.SetStatusBarColor(Android.Graphics.Color.Rgb(0, 72, 224));
        }
}

My AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="13" android:versionName="1.4" package="XXXXX" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
    <application android:label="XXXXX" android:icon="@mipmap/icon" android:usesCleartextTraffic="true" android:roundIcon="@mipmap/icon_round">
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/firebase1" />
        <service android:name="XXXXX.MyFirebaseMessagingService" android:stopWithTask="false" />
        <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
        <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

I am using the https://github.com/CrossGeeks/FirebasePushNotificationPlugin plugin to handle Firebase Notifications.

Any help is appreciated.
Thank You.

Rotation for videoplayer in xamarn

$
0
0
xmlns:video="clr-namespace:proj.Controls.Video"
 <video:VideoPlayer x:Name="videoPlayer" AreTransportControlsEnabled = "False"
                           Grid.Row="0" AutoPlay="False"/>
 private void Rotate_Clicked(object sender, EventArgs e)
        {
            if (videoPlayer.sRotate == false)
            {
                videoPlayer.sRotate = true;
            }
            else
            {
                videoPlayer.sRotate = false;
            }
        }

The videoPlayer.sRotate is Enable in Android and IOSis not work.Is something other need for IOS or Any Other way for rotate the videoplayer

Zoom-function for Cross-platform-project (Android, IOS, UWP)

Pages not loading. Problem with processing

$
0
0

I hope this isn't a repost. I posted my question, but can't find it. If so, sorry.

Hi Everyone! I am really trying to love Xamarin, but I'm running into some await / async / Page Load issues.
If anyone has any suggestions as to what I am doing wrong, feedback would be greatly appreciated!
The user starts my game in PlayersHandPage() and from there selects cards and clicks Play which, in turn,
calls public static async Task PlayCards() in App.Xaml.cs (below). I've tried all sorts of variations as to
what gets an async and what does not. I'm certain I'm doing something wrong! :X

In it's current state, what is happening is that while loop in "public static async Task PlayCards()"
runs forever and, on the screen, the PlayerHandPage() freezes. I can see the StateGridPage() call execute
in App.SetMainPage(new StateGridPage()); but the page never loads (on the screen) and the while loop
immediately continues looping.

Thank you again for any help! I am baffled.


//Code in App.Xaml.CS

public static async Task SetMainPage(Page newPage)
{
    Task.Run(async () =>
    {
        //await Task.Delay(500); // was 300
        Device.BeginInvokeOnMainThread(() =>
        {
            App.Current.MainPage = newPage;
        });
    });
}

// This method gets called from the PlayersHandPage().  There is a play button that gets
// pressed.  My intention is for the user, then, to be done with the PlayersHandPage,
// processing will then take place in App.Xaml.cs which will decide, via GameFunctions.PlayCard
// whether the StateGridPage (state chooser) needs to be called or whether the PlayersHandPage()
// should be reloaded.
public static async Task PlayCards()
{
    while (CurrentGame.CurrentSelectedCards.Count > 0)
    {
        await GameFunctions.PlayCard(App.CurrentGame.CurrentSelectedCards.FirstOrDefault());
    }
    SetMainPage(new PlayersHandPage());
}

//Code in GameFunctions
public static async Task PlayCard(KeyValuePair<Int32, Models.Card> myCard)
{
  // Play Card was designed to work like a state engine.  Basically, my
  // intention is to call it over and over until all cards are finished being
  // processed.  In the case of the DEA Agent, a state needs to be chosen
  // so I am trying to send the user to the StateGridPage which sets
  // App.CurrentGame.SelectedState.  Then, when the method is called again
  // it should assign the value it retrieved by calling the StateGridPage,
  // discard the card, and reload the PlayersHandPage which kicked off the
  // whole process when the user selected a card and clicked the play button
  // which in turn called PlayCards() in App.xaml.cs.
  //

switch (myCard.Value.CardType)
{
    case (Models.Card.CardTypes.DEAAgent):

        // First check to see if there are any places for a DEA Agent
        Dictionary<string, Models.USState> PossibleStates = App.CurrentGame.States.Where(x => !x.Value.HasDEA).ToDictionary(x => x.Key, x => x.Value);

    if (App.CurrentGame.CardAction.SelectedState.Length == 0) // Nothing has been done yet
    {
        App.CurrentGame.CardAction.Clear(myCard.Key, Models.CardSteps.PlayerActions.PlaceDEAAgent);
        App.CurrentGame.CardAction.Message = "Where do you want to place the DEA Agent?";

        // Navigate to State Grid 
        App.SetMainPage(new StateGridPage()); // Here I am calling the StateGridPage so the user can pick a state for the card
    }
    else // A card has already been selected
    {
        // Mark to Remove from player's hand
        alRemove.Add(myCard.Key); // Since the card is no longer in the players hand, there would be no more selected cards
                                  // however, I am currently not getting this far because the StateGridPage() is not appearing
                                  // to let me choose a state

        // Add to discard pile
        App.CurrentGame.DiscardPile.Add(myCard.Key, myCard.Value);

        // Make sure nothing else has the DEA card
        foreach (String strStateName in App.CurrentGame.States.Keys)
            App.CurrentGame.States[strStateName].HasDEA = false;

        // Move the DEA card to this state
        App.CurrentGame.States[App.CurrentGame.CardAction.SelectedState].HasDEA = true;

        // Clear the card action because we are done
        App.CurrentGame.CardAction.Clear();
    }
        break;

How to make the app open on the same place you left it last time?

$
0
0

Hi everyone, first question ever.
I am very new on Xamarin, making my first project, so I would very much appreciate detailed answers.

My app consists basically on a book. I am using CarouselPage, in which every chapter of the book is one of the carousel pages.

My question is how do I make sure that every time someone runs the app, it "saves the progress" and opens where you left it last time.

Thanks everyone!


Microcharts animation

Change color of button image-source

$
0
0

Hello, I need to change the color from an imagesource of a button. I found this plugin: https://github.com/shrutinambiar/xamarin-forms-tinted-image but the first problem is that its outdated and doesn't work on android. The second problem is that I need to change the color of a button imagesource and not of an image. I tried to create an image and use it as imagesource but this didn't work. Is there any solution to change the color of an imagesource of a button? Thanks in advance.

how to query a child element, present inside a list item

$
0
0

I want to automate the below scenario :
The List has several rows and each row has different elements inside it.
I want to iterate through the list and find elements inside each row using Xamarin.

IList CellList= app.Query(thisObject => thisObject.Id("MyList_ID"));

foreach(var element in CellList)
{

//Here i want to go inside each row and find an element inside each row. So what needs to be changed in the below line of code ?

bool isNTextPresent = (app.Query(thisObject => thisObject.Id("NText_ID")).Length) == 1 ? true : false;
Assert.AreEqual(isNTextPresent , true);
}

InsertAsync Xamarin Invalid data type provided

$
0
0

I have a problem with the InsertAsync function. I hope I'm not disturbing. The object I'm trying to insert is called User, it has 3 properties Id, username & password. When I call the InsertAsync() method (without giving any id and having the ID autoincrement on and IDENTITY_INSERT OFF) it throws an invalid data type provided error. If I delete the identity on id and I set an id value from the code it works. But I want it to work with the autoincrement method. Thank you!

How to detect scroll in Shell Flyout?

$
0
0

Hi!
I set FlyoutHeaderBehavior="CollapseOnScroll" and want to hide user image and show user name only when it is collapsed. How can I detect header collapsing?
Thanks!


Viewing all 89864 articles
Browse latest View live