Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Xamarin and Ncalc

$
0
0

Hello,

I am trying to use Nuget Ncalc library with Xamarin.
It works fine with WPF, but for some reason it does not with Xamarin.

My simple test in Xamarin is given below. It evaluates a simple expression X+Y where X=5 and Y=7.
During evaluation it fails with NullReferenceException. In WPF same code works fine.
Actually in Xamarin it does not even construct expression expr properly and it does not register properly parameters X and Y.
There is some incompatibility that I cannot understand. I tried various versions of NCalc. I also tried bot Xamarin variations: Shared and Netstandard.

I am looking for solution. Can anybody help or comment ?

Code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using NCalc;

namespace NcalcTestXamarin
{
public partial class MainPage : ContentPage
{
public MainPage()
{
Expression expr = new Expression("x+y", EvaluateOptions.IgnoreCase);

        expr.Parameters["x"] = 5;
        expr.Parameters["y"] = 7;

        string result = (string)expr.Evaluate();

        Label header = new Label
        {
            Text = result,
            FontSize = 50,
            FontAttributes = FontAttributes.Bold,
            HorizontalOptions = LayoutOptions.Center
        };

        Content = new StackLayout
        {
            Children =
            {
                header    
            }
        };
    }
}

}


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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