【问题标题】:The name "CartesianChart" does not exist in the namespace "using:LiveCharts.Uwp"名称空间“using:LiveCharts.Uwp”中不存在名称“CartesianChart”
【发布时间】:2017-10-11 13:38:10
【问题描述】:

我正在尝试在 UWP 应用中使用 LiveCharts 库。我通过 NuGet 安装了 LiveCharts 和 LiveCharts.Uwp。我按照 LiveCharts 网站上提供的步骤重新创建了他们的第一个示例,但我总是在 XAML 文件中收到以下错误:

  • 命名空间“using:LiveCharts.Uwp”中不存在名称“CartesianChart”

  • 在“CartesianChart”类型中找不到属性“Series”。

(见附两张图)。

XAML code and Errors

C# code and Solution Explorer

下面是我的MainPage.xaml和MainPage.xaml.cs的代码:

MainPage.xaml:

<Page
    x:Class="LC2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:LC2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:lvc="using:LiveCharts.Uwp"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <lvc:CartesianChart Series="{Binding SeriesCollection}" />
    </Grid>
</Page>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Controls;
using LiveCharts;
using LiveCharts.Uwp;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace LC2
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            SeriesCollection = new SeriesCollection
            {
                new LineSeries
                {
                    Values = new ChartValues<double> { 3, 5, 7, 4 }
                },
                new BarSeries
                {
                    Values = new ChartValues<decimal> { 5, 6, 2, 7 }
                }
            };
        }
        public SeriesCollection SeriesCollection { get; set; }
    }
}

【问题讨论】:

    标签: uwp livecharts


    【解决方案1】:

    我无法重现此问题。我使用 Visual Studio 2017 并使用此命令行:“PM> Install-Package LiveCharts.Uwp”。看起来您尚未成功添加引用 LiveCharts.UWP。尝试清除 Nuget 缓存并再次安装包。 Here 是关于如何清除缓存的参考。

    【讨论】:

      【解决方案2】:

      您是否尝试过清理您的项目? 右键单击解决方案-> 清洁解决方案。

      如果它不起作用,我也会尝试手动删除 bin 和 obj 文件夹。

      【讨论】:

        猜你喜欢
        • 2016-11-06
        • 1970-01-01
        • 2013-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-16
        • 2012-12-06
        • 2016-11-29
        相关资源
        最近更新 更多