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

Customising Microcharts

$
0
0

I'm trying to achieve the chart similar to the attached screenshot and I'm almost there. The only problem is, how can I put values in each arc of the chart? I'm using Microchart library.

    void PopulateChart()
    {
        var data = new[]
        {
            new Microcharts.Entry(50)
            {
                ValueLabel = "50",
                Color = SKColor.Parse("#104950")
            },
            new Microcharts.Entry(70)
            {
                ValueLabel = "70",
                Color = SKColor.Parse("#F7A4B9")
            },
            new Microcharts.Entry(90)
            {
                ValueLabel = "90",
                Color = SKColor.Parse("#0084b4")
            }
        };

        this.chartView.Chart = new TemperatureChart() { Entries = data };
    }

using Microcharts;
using SkiaSharp;
using System;
using System.Linq;

namespace chart
{
    public class TemperatureChart : Chart
    {
        public TemperatureChart()
        {
            BackgroundColor = SKColor.Parse("#F6F1E9");
        }

        public float CaptionMargin { get; set; } = 12;

        public float LineSize { get; set; } = 18;

        public float StartAngle { get; set; } = -180;

        private float AbsoluteMinimum => Entries.Select(x => x.Value).Concat(new[] { MaxValue, MinValue, InternalMinValue ?? 0 }).Min(x => Math.Abs(x));

        private float AbsoluteMaximum => Entries.Select(x => x.Value).Concat(new[] { MaxValue, MinValue, InternalMinValue ?? 0 }).Max(x => Math.Abs(x));

        private float ValueRange => AbsoluteMaximum - AbsoluteMinimum;

        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            var sumValue = Entries.Sum(x => Math.Abs(x.Value));
            var radius = (Math.Min(width, height) - (2 * Margin)) / 2;
            var cx = width / 2;
            var cy = Convert.ToInt32(height / 1.25);
            var lineWidth = (LineSize < 0) ? (radius / ((Entries.Count() + 1) * 2)) : LineSize;
            var radiusSpace = lineWidth * 4;

            foreach (var entry in Entries.OrderByDescending(e => e.Value))
            {
                DrawChart(canvas, entry, radiusSpace, cx, cy, lineWidth);
            }

            DrawCaption(canvas, cx, cy, radiusSpace);
        }

        public void DrawChart(SKCanvas canvas, Entry entry, float radius, int cx, int cy, float strokeWidth)
        {
            using (var paint = new SKPaint
            {
                Style = SKPaintStyle.Stroke,
                StrokeWidth = strokeWidth,
                StrokeCap = SKStrokeCap.Round,
                Color = entry.Color,
                IsAntialias = true
            })
            {
                using (SKPath path = new SKPath())
                {
                    var sweepAngle = 180 * (Math.Abs(entry.Value) - AbsoluteMinimum) / ValueRange;
                    path.AddArc(SKRect.Create(cx - radius, cy - radius, 2 * radius, 2 * radius), StartAngle, sweepAngle);
                    canvas.DrawPath(path, paint);
                }
            }
        }

        private void DrawCaption(SKCanvas canvas, int cx, int cy, float radius)
        {
            var minimum = 0;
            var medium = Math.Round(Entries.Max(e => e.Value) / 2);
            var maximum = Entries.Max(e => e.Value);

            canvas.DrawCaptionLabels(string.Empty, SKColor.Empty, $"{minimum}°", SKColors.Black, LabelTextSize, new SKPoint(cx - radius - LineSize - CaptionMargin, cy), SKTextAlign.Center);
            canvas.DrawCaptionLabels(string.Empty, SKColor.Empty, $"{medium}°", SKColors.Black, LabelTextSize, new SKPoint(cx, cy - radius - LineSize), SKTextAlign.Center);
            canvas.DrawCaptionLabels(string.Empty, SKColor.Empty, $"{maximum}°", SKColors.Black, LabelTextSize, new SKPoint(cx + radius + LineSize + CaptionMargin, cy), SKTextAlign.Center);
        }
    }
}

Detect and Open another App on device

$
0
0

Can someone tell me the best approach to accomplishing this for IOS and Android. Code samples or links to related discussions would be most appreciated.

thanks

Given Key Not Present in Dictionary Xamarin Forms

$
0
0

I Have a Login ViewModel something like this below

public class LoginViewModel : ViewModelBase
    {

        private readonly IAuthenticationService _authenticationService;

        public LoginViewModel(IAuthenticationService authenticationService)
        {
            _authenticationService = authenticationService;
        }
  }

And i'm Binding like this in XAML

<ContentPage.BindingContext>
    <viewModels:LoginViewModel />
</ContentPage.BindingContext>

When i Compile i'm getting "Given Key Not Present in Dictionary"

But when i add an Empty Constructor to My ViewModel like this

      public LoginViewModel ()
            {

            }

It working fine ,so is there any workaround for this other than instantiating from Code behind of my ViewPage ?

Is there how to debug xaml?

$
0
0

I have a xaml file and this file doen't work. But i don't know what's happening, then i ask: Is there how to debug this file? I need to know where is broken, where is issue. I use Visual Studio 2017 and Xamarin.Forms

xamarin forms linker and prism.dryioc

$
0
0

Soo, when we use Xamarin Forms, we want a small apk size. To achieve that we have Linker and Proguard.
But using Prism.Dryioc I got stuck, I really don't know how to properly setup my Link configuration file.

With this file(linker configuration) I just got a "System.TypeInitializationException: The type initializer for 'Registry' threw an exception."
Can someone help me to find the way to make Linker works?

Xamarin Forms: Hide a Stack While Scrolling a list

$
0
0

I have a Xamarin forms Page which is divided in 2 sections, the top 40% contains the Search controls inside a stack layout , the other 60% contains a list view. While scrolling the list view up i want to hide the Stack Layout at top covering 40% of the screen.

I achieved to implement scroll events of list from a reference on Stackoverflow and GitHub.

I am able to hide the stackLayout but there is lot of flickering. Any idea how can i stop the flickering? the output is not crisp and stable.

Cannot Crop or Resize Images on Windows Universal (UWP)

$
0
0

I have spent 2 days trying to resize and crop an image on UWP. I have it working on iOS and Android, but nothing seems to work on UWP. I am trying to use WritableBitmapExtensions from Nuget, but I cannot find the right combinations of calls to make it work. My left arm for a snippet showing how to:

byte[] image -> WritableBitmap.Crop -> back to image byte[]

This is a Xam.Forms project and I am trying to do the resizing in the Windows Universal project.

Thank you so much!

Line below group header

$
0
0

Can it be true that this bug still not have been corrected on Forms-iOS?
I use a custom listview renderer, if I remove separator line the lines between list view items disappear but below group headers the lines are still present. The lines are pure white, color can't be changed, and that is not very nice compared to my color palette on pages...
Please advice Xamarin crew.


Problem creating a renderer for a custom Switch using XamarinForms

$
0
0

So, I'm working on a Android app project in which I need to create a Switch control with customized text for the toggled options. I've tried creating a custom text Switch using a custom Renderer, but have had an exception whenever I try using my custom control.

I've created a custom TextSwitch control:

using System;
using AutoLogSchedulingMobile.Resources;
using Xamarin.Forms;


namespace AutoLogSchedulingMobile.CustomControls
{
    public class TextSwitch : Switch
    {
        public string TextOn
        {
            get { return "OK"; }
        }

        public string TextOff
        {
            get { return "NÂO OK"; }
        }
    }
}

And for the renderer:

using System;
using Android.Content;
using Android.Widget;
using AutoLogSchedulingMobile.CustomControls;
using AutoLogSchedulingMobile.Droid.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Switch = Android.Widget.Switch;

[assembly: ExportRenderer(typeof(TextSwitch), typeof(TextSwitchRenderer))]
namespace AutoLogSchedulingMobile.Droid.Controls
{

    public class TextSwitchRenderer : ViewRenderer<TextSwitch, Switch>
    {
        public TextSwitchRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<TextSwitch> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null)
            {
                this.Element.Toggled -= ElementToggled;
                return;
            }

            if (this.Element == null)
            {
                return;
            }

            var switchControl = new Switch(Context)
            {
                TextOn = this.Element.TextOn,
                TextOff = this.Element.TextOff
            };

            switchControl.CheckedChange += ControlValueChanged;
            this.Element.Toggled += ElementToggled;

            this.SetNativeControl(switchControl);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                this.Control.CheckedChange -= this.ControlValueChanged;
                this.Element.Toggled -= ElementToggled;
            }

            base.Dispose(disposing);
        }

        private void ElementToggled(object sender, ToggledEventArgs e)
        {
            this.Control.Checked = this.Element.IsToggled;
        }

        private void ControlValueChanged(object sender, EventArgs e)
        {
            this.Element.IsToggled = this.Control.Checked;
        }
    }

}

I am however getting a System.Reflection.TargetInvocationException whenever I try using this custom Switch control in any xaml page in my app. I'm not sure where the mistake is or if there is another way to implement a custom Switch with text using Xamarin forms. I'm attaching a copy of the output in a text file. I'd be grateful for any pointers.

Using MessagingCenter to send message from ViewModel to Xaml Code behind

$
0
0

Hi

I need to display some text in a textbox for ongoing debug purposes. In my codebehind for my Xaml page, I have:

protected override void OnAppearing(
{
            base.OnAppearing();
            MessagingCenter.Subscribe<string>(this, "UpdateStatus",(arg) =>
            {
                StatusText.Text += $"\n{DateTime.Now:HH:mm:ss}: {arg}";
            });
}

On my ViewModel, I have:

StatusTextText = new Command(() => { MessagingCenter.Send("UpdateStatus", "Searching For Device"); });

On My XAML, I have:

<Button Margin="0,10,0,0" Text="Find Device" Command="{Binding StatusTextText }" BackgroundColor="{StaticResource Primary}" TextColor="White" />

<Editor x:Name="StatusText"
                        VerticalOptions="FillAndExpand"
                        Focused="OnStatusTextFocussed"
                        FontSize="Micro"/>

The view displays and the MessagingCenter.Subscribe line is executed without error. When I click the button, I an see in the debugger that the code on the viewmodel runs, calling MessagingCenter.Send, but the message "Searching For Device" never shows up in the StatusText.

I am lead to believe that the Messaging Centre is global, any client to any subscriber. I have simplified it removing the class names to ensure that it is global, but still the message fails to arrive at the other end.

Any Ideas?

Nigel

How to show current slider value on thumb

$
0
0

Hello,

I checked the forum and did a search on the web but couldn't find something similar to what I want to achieve. Below is an image of what I want:
Image: vgy.me/0GUNVB.png

It's basically a slider where the current value is shown on the thumb.
Can it be done with custom renderers? If yes, is anyone have example project that I can examine the codes?

Thanks.

Xamarin Forms app is crashing with unknown reason

$
0
0

Hello guys

I have a lot of crash reports in Google Play Console for my xamarin.forms app without any understandable stack trace and possibility to get the reason of the issue. There is only the message below:

tgkill

backtrace:
  #00  pc 000000000004a230  /system/lib/libc.so (tgkill+12)
  #01  pc 00000000000479c3  /system/lib/libc.so (pthread_kill+34)
  #02  pc 000000000001d9c5  /system/lib/libc.so (raise+10)
  #03  pc 0000000000019511  /system/lib/libc.so (__libc_android_abort+34)
  #04  pc 0000000000017150  /system/lib/libc.so (abort+4)
  #05  pc 0000000000284ec4  /data/app/com.nyxbull.nswallet-2/lib/arm/libmonosgen-2.0.so

That's it.
Could anybody help me to understand how to catch actual reason of the issue in this case?

Thanks!

How to user AWS Cognito to Sign-in and Sign-up users

$
0
0

Does anyone know how to use AWS Cognito handle user registration and sign in for a mobile app? I have been trying to find examples/tutorials online for a while now but can't seem to find anything that will fit what I am looking for.

I have been following this guide but it doesn't seem to have anything to handle the sign in and sign up:
http://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/getting-started-xamarin.html

In my search I found that you can access CognitoUserPool in a PCL by adding the Amazon.Extensions.CognitoAuthentication Nuget package which is used in this tutorial for android:
http://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-android-sdk.html#using-amazon-cognito-user-identity-pools-android-sdk-register

I have also looked at the Xamarin example provided (https://github.com/xamarin/xamarin-forms-samples/tree/master/WebServices/TodoAWSAuth) but that is using Google as an authentication provider. I need to be able to have a custom login/sign up page.

TabbedPage binding to SelectedItem - no response

$
0
0

I have the following in my xaml:

<TabbedPage SelectedItem="{Binding CurrentTab}">
<Children>
    <local:HomepageView />
    <local:OtherPageView />
</Children>
</TabbedPage>

In my viewModel I've got:

private Page currentTab;

    public Page CurrentTab
    {
        get
        {
            return currentTab;
        }

        set
        {
            currentTab = value;
            OnPropertyChanged("CurrentTab");
        }
    }

However, the binding never fires! Anyone know what needs to be done to make this work?

ListView and AlternatingRowBackground - How to Refresh?

$
0
0

I have a ListView of items, where i want the alternating rows to have a different background color.
I have achieved this, using a CustomConverter and then updating the BackgroundColor there.

Unfortunately, this is not updated after I delete an item from the Row.
Can anyone offer suggestions on how to force a Refresh or how to Trigger the Converter again?


I Added my Custom Converter as a Global Resources in my App.xaml file
<Color x:Key="BorderColor">#FF0000</Color>
<infrastructure:BackgroundConverter x:Key="bgColorPicker" OddRowColor="{StaticResource BorderColor}"/>

The Code for my BackgroundConverter class:
The ObservableProperty is a custom class the supplies the SetProperty function, to save code.

public class BackgroundConverter : ObservableProperty, IValueConverter
{
    Color _evenRowColor = Color.White;
    Color _oddRowColor = Color.Gray;
    public Color EvenRowColor
    {
        get { return _evenRowColor; }
        set { SetProperty(ref _evenRowColor, value, nameof(EvenRowColor)); }
    }

    public Color OddRowColor
    {
        get { return _oddRowColor; }
        set { SetProperty(ref _oddRowColor, value, nameof(OddRowColor)); }
    }

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        int index = 0;
        foreach (var itm in (parameter as ListView).ItemsSource)
        {
            if (itm != value)
                index++;
            else
            {
                return (index % 2 == 0) ? EvenRowColor : OddRowColor;
            }
        }
        return EvenRowColor;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return EvenRowColor;
    }
}

Google in App purchases in Amazon Store

$
0
0

Is it possible to use google in app purchases in amazon store? maybe just for basic usage for example in app purchases is for removing ads.
Or we have to implement Amazon in app purchases. Is there any xamarin plugin for that?

Performance - Embedded Images or Local images best

$
0
0

For better performance of the application (mostly for Android) which is best way (Embedded Images or Local images) to access the image file.

Could not resolve type with token 01000012

$
0
0

I've been developing my app now for at least 5 months. I've been wanting to try the xamarin previewer so i updates visual studio xamarin forms and then i updated my nuget xamarin forms for my portable, ios and android.

now when i try to debug the application on the device i get

System.TypeLoadException: Could not resolve type with token 01000012

on this line

global::Xamarin.Forms.Forms.Init(this, bundle);

which i find very odd

origionally my xamarin forms nuget version was 2.3.3.168

so i thought id update to the stable version which was the same version number 2.3.3.168 but it had "stable" beside it

i've downgraded again but still get the same error.

any thoughts

thanks

How to increase seekbar thumb size?

$
0
0

Hi guys,
the xamarin.forms slider is a seekbar on android. The default thumb on android is so small that you nearly can't grab it. Thats the reason why I would like to increase its size.

I implemented an effect to achieve this but when i set a new thumb, the whole seekbar gets higher and I found no way to control it programmatically.

Android seekbar:

what i want:

what i get:

any idea how to fix it?

new Navigation.RemovePage not working

$
0
0
                var preCount = this.Navigation.NavigationStack.Count;

                        this.Navigation.RemovePage(this.Navigation.NavigationStack.Last());

                var postCount = this.Navigation.NavigationStack.Count;

preCount and postCount are both the same. How is this possible?

Viewing all 79144 articles
Browse latest View live


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