无法识别Xamarin Microcharts扩展名称空间

时间:2017-09-12 00:39:33

标签: xml xaml xamarin.ios xamarin.forms xamarin.android

我目前正在使用Xamarin表单构建应用程序。我试图让一个简单的图表元素在加载时出现在页面上。

我已经安装了AloïsDeniel的Microcharts.Forms v0.6.2软件包,用于我的Xamarin表单应用程序。

当我将<forms:ChartView x:Name="Chart1"/>行添加到我的LiteChartPage.xaml文件中时,在编译时我收到此错误。

'forms' is an undeclared prefix. Line 8, position 6.

我的using Microcharts;文件中有LiteChartPage.xaml.cs

这是我的xaml代码

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App1"
             xmlns:chart="clr-namespace:Microcharts.Forms;assembly=Microcharts.Forms"
             x:Class="App1.LiteChartPage">
        <forms:ChartView x:Name="Chart1"/>
</ContentPage>

以下是LiteChartPage.xaml.cs代码:

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

using static SkiaSharp.SKCanvas;
using Microcharts;
using Entry = Microcharts.Entry;

namespace App1
{
    public partial class LiteChartPage : ContentPage
    {
        public LiteChartPage()
        {
            Microcharts.Chart c = new Microcharts.BarChart();
            List<Microcharts.Entry> entries = new List<Microcharts.Entry>
            {
                new Microcharts.Entry(200)
                {
                    Color = SkiaSharp.SKColor.Parse("#FF1493"),
                    Label = "Litecoin Price",
                    ValueLabel = "200"
                },
                new Microcharts.Entry(400)
                {
                    Color = SkiaSharp.SKColor.Parse("#BB1493"),
                    Label = "Bitcoin Price",
                    ValueLabel = "200"
                },
                new Microcharts.Entry(-100)
                {
                    Color = SkiaSharp.SKColor.Parse("#FFBBD3"),
                    Label = "Etherium Price",
                    ValueLabel = "200"
                },
            };
            c.Entries = entries;      
            InitializeComponent();

        }
    }
}

我是否需要在某处添加对forms命名空间的引用?

3 个答案:

答案 0 :(得分:3)

更改前缀为。因为在这里您在内容页面中将名称空间声明为图表但使用表单。

答案 1 :(得分:0)

您已将命名空间定义为:

xmlns:chart="clr-namespace:Microcharts.Forms;assembly=Microcharts.Forms"

这意味着在您的XAML中,您应该使用定义NS 图表而不是表单

答案 2 :(得分:0)

我相信您安装了MicroCharts块,所以您的问题可能是您使用的是.NET标准2.0,而该块不支持它。要解决此问题,您应该安装此块的最新预发行版。它支持.NET标准2.0