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

How to make a squared image to a round image on xamarin forms ?

$
0
0

Is it possible to make a round image on Xamarin Forms of a squared image. I have a lot of images which should be displayed as a circle on ListView along with its name etc. But how can I do this?


<Ellipse.Fill>

</Ellipse.Fill>

I tried like this, but it is not working and it threw an error "Type ImageBrush not found in xmlns http://xamarin.com/schemas/2014/forms"


Clear cache in Webview Xamarin forms?

$
0
0

I have login in Webview, after authentication I am navigating to Dashboard page. After click on log-out(in dashboard) I navigate back to login-page which has WebView, but still WebView retains token. So how to clear cache(token) or is there any way to have LoginPage in WebView

How to fix 'Task could not find "al.exe" using the SdkToolsPath' Error?

$
0
0

I am getting the below compile time error. Visual studio (2019) version is 16.3.3. and .net framework is 4.8.03752.How to fix it? Any suggestion please.

Task could not find "al.exe" using the SdkToolsPath "" or
the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\NETFXSDK\4.7.2\WinSDK-NetFx40Tools-x86".
Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under
the SdkToolsPath and that the Microsoft Windows SDK is installed.

How to change Text Atribute of Label using FadeTo Method when a Toggle Control in View is pressed

$
0
0

Hello everyone, this is my very first question, i just suscribed, I am using MVVM pattern and i need to change the Text value of a label in my View, when i press a toggle control. The thing is, when i switch between two values of text, the label shows a kind of unwanted blink before take the new value, according to this, i was wondering if using FadeTo method, i could avoid this effect of blink. Please, any idea on how to achieve this would be very appreciated. thanks in advance.

public bool KgToggled
{
get
{
ModifyTextAmount(_kgToggled);
return _kgToggled;
}
set => SetProperty(ref _kgToggled, value);
}

    private void ModifyTextAmount(bool flag)
    {
        TextLabelKg = flag ? "By Kg" : "By Head";
        Amount = flag ? Price * Kg : Price * Heads;
    }

From Listview to Slider showing details

$
0
0

Have a Listview and with SelectedItemChangedEvent the details are showing on other page

Works fine.

But i found a Slider and is it possible to show the details in the Slider on the same page as the Listview and not on the other page ?

Fill the Listview from a Firebase database.

The Slider i made

https://xamaringuyshow.com/2020/06/21/xamarin-forms-bottom-slider/?utm_campaign=Weekly%2BXamarin&utm_medium=email&utm_source=Weekly_Xamarin_265 

Go to other page and show the details

async  void lstBal_ItemSelected(System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
        {

                if (e.SelectedItem != null)
                {
                    await Navigation.PushAsync(new Waar
                    {
                        BindingContext = e.SelectedItem as Person
                    });
                lstBal.SelectedItem = null;
            }

        }

Why do I get an error of type Okhttp instead of http when I am trying to authenticate with Google?

$
0
0

Hi!I am trying to create google authentication and everything seems to work fine,I can see the details of the user when I debug the app but for some reason it just breaks with this error: "Java.IO.IOException: 'unexpected end of stream on com.android.okhttp.Address@e8dfea7b' ".I found a similar post which describes the same problem:https://stackoverflow.com/questions/54308376/how-to-fix-a-java-io-ioexception-unexpected-end-of-stream-on-connection-excep .I did exactly what it was suggested by checking,in the Advanced Properties of the Android app, the HttpClient which was set by default to Android along with SSL/TLS Implementation on Native TLS 1.2+.I checked to see if I have System.Net.Http in my assemblies and it is there but for some reason it still returns an OKHttp error and I don't understand why.I looked over similar issues from users that experienced the same problem and most of them had a problem with the Advanced Properties of the Android application which were easily resolvable or with OKHttp used with Retrofit(this is not my case).Did someone experienced a similar issue and has an efficient way of resolving this error?

Xamarin.Forms Android App Restarts after Camera taking photo

$
0
0

I have a Xamarin. Forms application, and when the application starts everything working fine. After that, I want to take and store the photo using our phone's camera. Here the problem is when I was the open camera and taking the photo, After I click the save button it is not returning OnActivityResult Method. The camera that will be crashing the MainActivity.cs, Then XF is restarted and the app starts on the MainPage.

Xamarin.Forms Android - v3.5.0.274416

MainActivity.cs Code :-

      BtnCamera.ShouldTakePicture += () =>
                    {
                       var intent = new Intent(MediaStore.ActionImageCapture);
                        var filePath = CreateFilePath.GetFilePath();
                        Java.IO.File file;

                            file = new Java.IO.File(filePath, TruckDetails.TripID +  Guid.NewGuid().ToString() +".png");

                        (new Java.IO.File(filePath)).SetWritable(true, false);
                        intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
                         StartActivityForResult(intent, 100);
            };

PS :-
1. I am not used MediaPlugin DLL.
2. It is not happening every time.

App Center Log -:

    Android: 9
    Android Build: PPOS29.114-134-7-7
    Manufacturer: motorola
    Model: moto g(7) power
    CrashReporter Key: 1e8720f8-b0fb-42b5-bf1c-d6466eb00140
    Start Date: 2020-06-29T03:01:10.721Z
    Date: 2020-06-29T03:01:12.758Z

    Xamarin Exception Stack:
    System.NullReferenceException: Object reference not set to an instance of an object
      at Scoular.Droid.MainActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00240] in <4dd616694d1a48ffb7992593dad90b4a>:0
      at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <ff07eae8184a40a08e79049bbcb31a0e>:0
      at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <b62c3fba3fe848f3bb323dbe33464223>:0
      at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <b62c3fba3fe848f3bb323dbe33464223>:0
      at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <b62c3fba3fe848f3bb323dbe33464223>:0
      at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.29(intptr,intptr

Thanks advance :)

Compliance Info and Release notes are not updated in App Store

$
0
0

I am trying to submit app using appcenter but I am getting below error :
Oops! Compliance Info and Release notes are not updated in App Store. Alternatively, you can set 'ITSAppUsesNonExemptEncryption' flag in info.plist and redistribute

I have also re-tried adding below key, and I am still getting same error
<key>ITSAppUsesNonExemptEncryption</key> <false/>


No field mSelectorWheelPaint in class Landroid/widget/NumberPicker in API 29 (Android 10)

$
0
0

NumberPicker picker = new NumberPicker(Context); Java.Lang.Reflect.Field field = picker.Class.GetDeclaredField("mSelectorWheelPaint");

I am getting below mentioned exception. It only occurred with API 29 (Android 10)

Java.Lang.NoSuchFieldException: 'No field mSelectorWheelPaint in class Landroid/widget/NumberPicker; (declaration of 'android.widget.NumberPicker' appears in /system/framework/framework.jar!classes3.dex)'

admob sestdeviuceids for android

$
0
0

[Ads] Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("1C23F9449E0D92358C1D97543D4B5AC4") to get test ads on this device.

how do you do this in xamarin? using xamarin.googleplaysservices.ads

Can't select same item twice on CollectionView

$
0
0

I use a CollectionView control to display a list of files, if users click an item a popup appears displaying information about the file and a button to download it, the problem is that i use the SelectionChanged method of the CollectionView to run this action, but if users close the popup and click again on the same item nothing happens. Back when we use ListView control, the ItemTapped event runs every time the users click the same item, but i need to changed to CollectionView because later we'll change the file item from a single row to multiple columns (2 or 3).

It is possible to make the users click on the same item multiple times ?

P.D: also try to set the SelectedItem to null but the app crashes if the users select the same item.

Hi i want to take the data from a selected item in ListView but i get the last object created.

Hide time in status bar for Android and iOS

$
0
0

Hi, I would like to hide the time in the status bar for Android and iOS (but not for UWP), so I would like
to do it in the Platfrom Project, and not in the Xmarin.Forms project.

In iOS:
I understood I need to do it via info.plist.
1. In Application tab (Checking the Hide status bar check box).
2. In Source tab (Add a property of "Status bar is initially hidden" and setting it to "Yes").

The problem is that there is no such a tab "Source" (At least not in Visual Studio 2019).

In Android:
What is the equivalent file in Andorid for info.plist?

Thank you,
Eliran.

Problem with collection view update ui only on iOS

$
0
0

Hi All,

I have a problem with a vertical collectionview, when I fire an update of data in ViewModel the ui update the first and the third element but no the second on iOS, on Android work well like a charm. Do you know some trick to force ui update?

Thanks.

About skiasharp scale

$
0
0

I have a question about skiasharp's scale, but what does "canvas.Scale(2);" double?

For example, if the whole is 256x256, does "canvas.Scale(2);" result in 512x512?

Also, I don't clearly understand the difference between SKCanvasView and SKCanvas.

List<SKBitmap> bitmaps = new List<SKBitmap>();
private async void Pic()
{

    for (int i = 1; i <= 10; i++)
    {
        string url = "";

        url = "https://c.tile.openstreetmap.org/" + 18 + "/" + (233891 + i) + "/" + 100481 + ".png";


        try
        {
            var httpClient = new HttpClient();
            using (Stream stream = await httpClient.GetStreamAsync(url))
            using (MemoryStream memStream = new MemoryStream())
            {
                await stream.CopyToAsync(memStream);
                memStream.Seek(0, SeekOrigin.Begin);
                //helloBitmap = SKBitmap.Decode(memStream);
                bitmaps.Add(SKBitmap.Decode(memStream));
            }
        }
        catch(Exception e)
        {
        }
    }

    SKCanvasView canvasView = new SKCanvasView();
    canvasView.PaintSurface += OnCanvasViewPaintSurface;
    Content = new ScrollView { Content = canvasView, Orientation = ScrollOrientation.Horizontal };
}

private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{

    SKImageInfo info = args.Info;
    SKSurface surface = args.Surface;
    SKCanvas canvas = surface.Canvas;

    canvas.Scale(2);

    using (surface = SKSurface.Create(new SKImageInfo(1000, 1000)))
    {
        for (int i = 0; i < bitmaps.Count; i++)
        {
            canvas.DrawBitmap(bitmaps[i], 256 * i, 0, null);
        }
    }
}

How to establish button click in code behind

$
0
0

Hello,
I have created a form with grid which contains button and label.So the number or rows and columns vary according to my table.
i haved binded label and button text. now when i click a button i want the data which is binded to that clicked button.
Since number of rows and columns vary i have done this in code behind.Please help

<List> table=new <List>();
protected async override void OnAppearing()
        {
            //data for table is getting using webapi. im not giving that code
            count= table.Count;
            decimal rw = (decimal)table.Count / 3;
            decimal  RowCountRequired = Decimal.Ceiling(rw);
            var maxwidth = Application.Current.MainPage.Width;
            var width = maxwidth / 3;

            for (int currentRow = 0; currentRow < RowCountRequired; currentRow++)
            {
                count = count - ColumnCountRequired;
                for (int currentColumn = 0; currentColumn < ColumnCountRequired; currentColumn++)
                {
                        var label = new Label
                        {

                            HorizontalTextAlignment = TextAlignment.Center,
                            VerticalTextAlignment = TextAlignment.Center
                        };
                        label.SetBinding(Label.TextProperty, nameof(Table_Master.th_tableid));
                        gridLayout.Children.Add(label, currentColumn, currentRow);
                }
            }
            ColumnCountRequired = 3;
            count = table.Count;
            for (int currentRow = 0; currentRow < RowCountRequired; currentRow++)
            {
                gridLayout.RowDefinitions.Add(new RowDefinition { Height = 250});
                gridLayout.VerticalOptions = LayoutOptions.FillAndExpand;
                gridLayout.HorizontalOptions = LayoutOptions.FillAndExpand;
                if (count < 3)
                {
                    ColumnCountRequired =  count;
                } 
                count = count - ColumnCountRequired;
                for (int currentColumn = 0; currentColumn < ColumnCountRequired; currentColumn++)
                {
                    gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width =width});
                    Button button = new Button
                    {
                        TextColor=Color.White,
                        BackgroundColor = Color.Green,
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        HorizontalOptions = LayoutOptions.FillAndExpand,


                    };

                    button.SetBinding(Label.TextProperty, nameof(Table_Master.th_tablename));
                    button.Clicked += OnButtonClicked;
                    gridLayout.Children.Add(button    , currentColumn, currentRow);

                }

                // reduce the number of columns on the next row to simulate row span       
                // ColumnCountRequired = ColumnCountRequired - 1;

            }

            for (int i=0;i<table.Count; i++)
            {
                gridLayout.Children[i].BindingContext = table[i];
            }

                base.OnAppearing();
        }


private void OnButtonClicked(object sender, EventArgs e)
        {

// if i click row0,col0 th button i want data binded to label o ro0,col0
        }

Hiding Collection View Group Header

$
0
0

Is there any way we can hide CollectionView's group header if the group is empty when grouping is enabled?

Let's take the example from the official docs:

    // Extended List
    public class AnimalGroup : List<Animal>
    {
        public string Name { get; private set; }

        public AnimalGroup(string name, List<Animal> animals) : base(animals)
        {
            Name = name;
        }
    }

    // Viewmodel property
    public List<AnimalGroup> Animals { get; private set; } = new List<AnimalGroup>();

     // View
        <CollectionView ItemsSource="{Binding Animals}" IsGrouped="true">
            <CollectionView.GroupHeaderTemplate>
                <DataTemplate>
                    <Label Text="{Binding Name}"
                           BackgroundColor="LightGray"
                           FontSize="Large"
                           FontAttributes="Bold" />
                </DataTemplate>
            </CollectionView.GroupHeaderTemplate>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                ...............
            </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

Is it possible to hide the group header if the items of that header are empty?

ListView Itemsource

$
0
0

Dear Forum

I created a ListView, and I populated it with String, coming from a list..It is working:

List S_List = new List();
S_List.Add("A");
S_List.Add("B");
S_List.Add("C");

ListView LV1 = new ListView();
LV1.ItemsSource = S_List;

Content = LV1;

Now ,I want populate it with only 2 colored box (BoxView) ,but ,is not working:
//-- BoxView
BoxView BX1 = new BoxView();
BX1.Color = Color.Red;

BoxView BX2 = new BoxView();
BX2.Color = Color.Red;

List B_List = new List();
B_List.Add(BX1);
B_List.Add(BX2);

//ListView
ListView LV1 = new ListView();
LV1.ItemsSource = B_List;

Content = LV1;

I get 2 line with a string sayng Xamarin.Form.BoxView , that seems a conversion in String.

Why ?
Is possible to dont use DataTemplate, as shown in many example ?

Thanks
Roberto

Google authentication with oauth2 tutorial

$
0
0

Hello guys!

I am using xamarin for crossplatform ios/android about some moths now and also bought some tutorials in udemy about it. While a good portion of my app is completed i am wanted to use google calendar api and google authentication/sign in

I couldn't find a single completed tutorial how to do so and all the solutions i found online are either too complicated without structure or explanations , have details missing or refer to deleted links.

Is there someone who can provide me a good tutorial or example my top priority is to create a good working oauth2 google login and after that i can use i think easily google calendar with rest calls

Any help would be appreciated

here is one sample code i used that is not working

` Task OnLoginClickedAsync(object sender, EventArgs e)
{
string clientId = null;
string redirectUri = null;
string authorizeUri = Constants.AuthorizeUri;
string accessTokenUri = Constants.AuthorizeUri;
switch (Device.RuntimePlatform)
{
/* case Device.iOS:
clientId = Constants.iOSClientId;
redirectUri = Constants.iOSRedirectUrl;
break;*/

            case Device.Android:
                clientId = "152826923349-8n46ad52iub89udn4j7fds43nfmfc416.apps.googleusercontent.com";
                redirectUri = "com.companyname.manager:/oauth2redirect";
                break;
        }

        var authenticator = new OAuth2Authenticator(
            clientId,
            null,
            scope: "email",
            new Uri(authorizeUri),
            new Uri(redirectUri),
            new Uri(accessTokenUri),
            null,
            true);

        authenticator.Completed += OnAuthCompleted;
        authenticator.Error += OnAuthError;

        Xamarin.Auth.Authenticator auth = authenticator;

        var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
        presenter.Login(auth);

    }`

Xamarin.Forms with Prism:EventToCommandBehavior and xamarin.forms.map

$
0
0

Hi guys,
I'm trying to use EventToCommandBehavior that Prism provides with a Clicked event of xamarin.forms.map as the following:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
             x:Class="Solorrow_Prism.Views.MainPage"
             xmlns:prism="http://prismlibrary.com"
             Title="{Binding Title}">
<StackLayout>
        <maps:Map x:Name="map" MapType="Hybrid">
            <maps:Map.Behaviors>
                <prism:EventToCommandBehavior EventName="MapClicked"
                                          Command="{Binding MapClickedCommand}" />
            </maps:Map.Behaviors>
        </maps:Map>
        <Button Text="ClickMe!">
            <Button.Behaviors>
                <prism:EventToCommandBehavior EventName="Clicked"
                                          Command="{Binding MapClickedCommand}" />
            </Button.Behaviors>
        </Button>
    </StackLayout>
</ContentPage>

but unfortunately when running the app nothing shown in the emulator. when I comment out MapClicked event everything works fine. and the clicked event works fine for the button element. Is prism: EventToCommandBehavior doesn't support map element or I miss something? any help, please.

Viewing all 79144 articles
Browse latest View live


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