【发布时间】:2018-02-20 07:36:57
【问题描述】:
我目前正在 Xamarin 表单中构建应用程序。我试图让一个简单的图表元素在加载时出现在页面上。
我已经安装了 Aloïs Deniel 的 Microcharts.Forms v0.6.2 包,以便在我的 Xamarin 表单应用程序中使用。
当我将<forms:ChartView x:Name="Chart1"/> 行添加到我的LiteChartPage.xaml 文件中时,编译时出现此错误。
'forms' is an undeclared prefix. Line 8, position 6.
我的LiteChartPage.xaml.cs 文件中有using Microcharts;。
这是我的 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();
}
}
}
我是否需要在某处添加对表单命名空间的引用?
【问题讨论】:
-
您缺少“表单”的前缀声明 - 尝试使用
-
错误变为大写 F
Error CS0234 The type or namespace name 'Forms' does not exist in the namespace 'Microcharts' (are you missing an assembly reference? -
如果你错过了,我相信你也需要在你的项目中安装Microcharts.Forms nuget 包
标签: xml xaml xamarin.ios xamarin.forms xamarin.android