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

ListView behaviour in UWP project

$
0
0

I've just started working with Xamarin Forms and I'm trying to wrap my head around a couple of things that are (not) happening relating to a bound ListView, hopefully someone can shed some light on this for me.

    private Item _SelectedItem;        
    public Item SelectedItem;
    {
       get => _SelectedItem;
       set
       {
          _SelectedItem; = value;
          NotifyPropertyChanged("SelectedItem");
        }
    }

    public ObservableCollection<Item> ItemsList { get; set; }
    public ICommand RemoveItemCommand { get; private set; }


    public MyViewModel()
    {
       RemoveItemCommand = new Command(RemoveItem, CanRemoveItem);
    }

    private void RemoveItem()
    {
       ItemsList.Remove(SelectedItem);
    }

    private bool CanRemoveItem()
    {            
       return SelectedItem != null;
       //return true;
    }

And the Xaml:

  1. When a row is selected there is no visual indication that it has been selected (ie. row is not highlighted)

  2. When a row is selected, the SelectedItem property in my ViewModel contains the selected correct object, but the
    CanRemoveItem property of the command is never set to true so the button is always disabled. However, RemoveItem method and button work when CanRemoveItem is manually set to true.

Is this expected behaviour or am I missing the mark somewhere?


MagicGradient Deploy to iOS Device problem

$
0
0

It seems that using an older version of XCode (10.1) my application can't deploy to an iOS 13 device once I start using MagicGradients. (Based on research of the error).

It's such a shame because my app is almost done and there hasn't been any other problems or incompatibilities with other frameworks. As soon as I put this sample snippet into a XAML page I get the error that follows. If I take that out it deploys to my device with no errors (even though the Nuget packages are still installed and referenced).

``<magic:GradientView VerticalOptions="FillAndExpand">
magic:GradientView.GradientSource
<magic:LinearGradient Angle="90">
<magic:GradientStop Color="Red" Offset="0" />
<magic:GradientStop Color="Yellow" Offset="1" />
</magic:LinearGradient>
</magic:GradientView.GradientSource>
</magic:GradientView>

** error MT4109: Failed to compile the generated registrar code.**

Same code and app will deploy to an IOS Simulator without issue.

Hoping maybe someone knows what the cause is and I can perhaps still use this in my application.

How to get return value from javascript in xamarin.forms?

$
0
0

I am working on xamarin.forms. I have a javascript method in a html file that returns a value. I need to access that javascript method and get the return value. I tried to use WebView. But unfortunately the webview.Eval() method doesn't return any value. It is Void type.

Please tell me how I can access the javascript method with help of webview and will get the return value of that functions.

How to use Oauth2 in xamarin form?

$
0
0

I create login form and i want to using Oauth2, Can you give me a specific example? thanks you very much!

Options to Properly Add FireBase to My Xamarin Forms Project

$
0
0

Hi guys,

I need to use firebase Cloud Messaging in my project, decide to follow all the official microsoft guidelines but I have had some bugs trying to add dependencies.

First, when adding the json file generated by Firebase (google-services.json) in the Android project, I don't see the option to add the resource as **GoogleServiceJson **(Step: In Properties> Advanced> Build Action, select GoogleServicesJson.)

Second, when I try to add the NuGetPackage Xamarin.Firebase.Messaging in the android project it throws me the error the $ (TargetFrameworkVersion) for PGTApp.Android (v8.1) is less than the minimum required $ (TargetFrameworkVersion) for Xamarin.Forms ( 9.0).
I am clear where I have to change for this to be fixed, but it remains the same without being able to be added.

Finally, I have updated to the latest version of xamarin forms but still unable to enable Firebase in my project.

Some aspects of my project:
1. Xamarin Forms version: 4.6.0.800
2. .Net Standard version: 2.0
3. Xamarin.Firebase.Messaging version: 17.1740.1 (not installed)
4. Sdk version minimum Api16 and maximum Api29. For the Android project.

My main question is what other options can I have to use Firebase in my project or how can I solve this problem?

Thank you very much, Greetings from Panama

How can I load an image from an ImageSource to use in Skia?

shell or ContentPage not rtl

$
0
0

hi
my project Shell

FlowDirection="RightToLeft" not working

example CarouselView read 20 items, Move images from left to right

How did the whole project align rtl?

Unexpected Memory leaks shown by Xcode's Instrument tool

$
0
0

Hi,
I have a problem related to memory leaks shown by Xcode's Instrument tool.

I have used Visual Studio 2017 on windows 7 machine connected to mac build host.

I have created Xamarin project in Visual Studio 2017 as follows:

File->New->Project->Cross-Platform->Mobile App(Xamarin Forms)->Blank(iOS, .NET Standard)
Note: I have added No extra code from my side

This project is successfully executed on iPhone5s Simulator (12.1)

Then i used instrument tool (Leak Check)

It showed following leaks.

Question: Why these leaks occur on standard project and How to fix them.

Image-1

Image-2

Image-3

Image-4

Image-5_1

Image-5_2

Image-6

Image-7


ToolbarItems are displayed twice

$
0
0

hi,
when i exceute my single page of application then toolbar items are properly displayed ,but when i navigate the page then double icon are displayed .

code for toolbar item added in xaml file

App.xaml.cs in which i called the respective page

plz give me suggestion to how to solve this..

Setting Cookies in a WebView

$
0
0

I received a request this morning to share how I set cookies in a webview so here it is, hope it's helpful. It's worked for me so far but feel free to comment on it if it can be improved.
First, you have to create a custom render for your webview in iOS and Android, there are many examples of how to do that so I won't go into that here.
In my shared code I have a UserInfo object that contains a CookieContainer:

    public class UserInfo
    {
        public static CookieContainer CookieContainer = new CookieContainer();
    }

In my (native) login page I have an event called OnLoginClickAsync which validates the login information. I create a HTTPClientHandler:

                var handler =  new HttpClientHandler {CookieContainer = UserInfo.CookieContainer};
                var httpClient = new HttpClient(handler);

Then save the resulting CookieContainer if the validation is successful:

                UserInfo.CookieContainer = handler.CookieContainer;

On the Android side in the OnElementChanged event for my web view renderer I use:

            var cookieManager = CookieManager.Instance;
            cookieManager.SetAcceptCookie(true);
            cookieManager.RemoveAllCookie();
            var cookies = UserInfo.CookieContainer.GetCookies(new System.Uri(AppInfo.URL_BASE));
            for (var i = 0; i < cookies.Count; i++)
            {
                string cookieValue = cookies[i].Value;
                string cookieDomain = cookies[i].Domain;
                string cookieName = cookies[i].Name;
                cookieManager.SetCookie(cookieDomain, cookieName + "=" + cookieValue);
            }

On the iOS side in the OnElementChanged event for my web view renderer I use:

            // Set cookies here
            var cookieUrl = new Uri(AppInfo.URL_BASE);
            var cookieJar = NSHttpCookieStorage.SharedStorage;
            cookieJar.AcceptPolicy = NSHttpCookieAcceptPolicy.Always;
            foreach (var aCookie in cookieJar.Cookies)
            {
                cookieJar.DeleteCookie(aCookie);
            }

            var jCookies = UserInfo.CookieContainer.GetCookies(cookieUrl);
            IList<NSHttpCookie> eCookies = 
                (from object jCookie in jCookies 
                 where jCookie != null 
                 select (Cookie) jCookie 
                 into netCookie select new NSHttpCookie(netCookie)).ToList();
            cookieJar.SetCookies(eCookies.ToArray(), cookieUrl, cookieUrl);

Also, if you want to use the cookie container in a straight call - not in a webview - just set it in the handler:

            var handler = new HttpClientHandler { CookieContainer = cookieContainer };
            var httpClient = new HttpClient(handler);

get the imei number of the device

$
0
0

hi,
I want find the imei number of the device in xamarin forms .I have tryed the following solution but nothing is happen

This is serviceImei which implement the interface IServiceImei containg one function

And Mianpage having the following code

when i exceute this nothing is happen.
plz provide some suggestion.

Sendin a Object and getting List From Rest Api

$
0
0

i want to get i list from rest api by sendin parameters (as pbject), Ex.) i have a student table, i want to send an object that list should be specified and gettin list.. suppose that i ll send gander=male.. age=15 cource=math.. i ll send this and i want to get list and bind.

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!

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

CollectionView - Horiztonal - Full Width

$
0
0

I am trying to do a Collection View , Horizontal with each cell the full width of the screen.
I have to set the width the of the view within the data template as simply doing a "FillAndExpand" makes it wider than the screen.
So the question is how can I know the width of the screen to set this ?


Image not showing inXamarin Forms ImageCircle plugin

$
0
0

I am working on a Android App using Xamarin Forms. I have ImageCircle plugin added on my form to display profile image. I want to update it with the photo captured from the phone's camera. So to do this i have these pieces of code.

1. XAML

 <controls:CircleImage x:Name="ImgProfile" BorderColor="DarkSlateGray" BorderThickness="5"  Aspect="AspectFit"  Scale="0.6" HeightRequest="150" WidthRequest="150" />
                            <ImageButton Source="pan.png" BackgroundColor="Transparent" Clicked="ImageButton_Clicked"></ImageButton>

2. C#

async void TakePhoto()
        {
            await CrossMedia.Current.Initialize();
            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                PhotoSize = Plugin.Media.Abstractions.PhotoSize.Small,
                Name = Guid.NewGuid().ToString().Substring(0,8),
                Directory= "profile"
            });

            if(file==null)
            {
                return;
            }

            ImgProfile.Source=  ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                return stream;
            });
      /* tried this as well

var byteArray = File.ReadAllBytes(file.Path);

        ImgProfile.Source=  ImageSource.FromStream(()=> new MemoryStream( byteArray));

*/

        }

        private void ImageButton_Clicked(object sender, EventArgs e)
        {
            TakePhoto();

        }

I tried below ways as well, but no success:

  1. Setting Source = file.Path

  2. Using Byte Array

  3. {Binding ImageSource} in xaml and setting imagesource in code behind.

The above code is running fine, I can see byte array/stream as well in watch window.But still, Image is not displaying.

Please Note:

My approach is old school WinForm way not MVVM.

Plugins / Modules version

  1. VS 2019 Community 16.5.5

  2. Xamarin Android SDK - 10.2.0.100

  3. Xamarin.Forms 4.6.0.800

  4. Xamarin.Plugin.Media 5.0.1
  5. Xamarin.Plugins.Forms.ImageCircle 3.0.0.5

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);
}

How to get the current page in a Shell?

$
0
0

I have a Shell based app. When I respond to a push notification I want to handle it differently depending on which page the user is currently viewing. How can I get the current page?

I've found that Shell.Current.CurrentState.Location tells me the route of the current page. But, in addition to that, I would like to get the Page object. The reason is, in one case, in response to the notification, I would like to refresh the page. That page (or it's BindingContext) has that refresh functionality, but in order to execute it I need to get that Page object. How can I get that?

I believe that one way would be to listen to the Shell navigation events and keep track, but that seems like overkill. Surely there must be a simple way to determine the current page.

Thanks.

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.

Xamarin.Forms CardsView nuget package

$
0
0

Hi all) I've released new package for Xamarin.Forms (Something like Tinder's CardsView)
Maybe, someone will be interested in it

nuget.org/packages/CardsView/ -- nuget
github.com/AndreiMisiukevich/CardView -- source and samples

Viewing all 89864 articles
Browse latest View live


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