适用于UWP的Telerik:Windows.UI.Xaml.UnhandledException

时间:2018-08-05 18:15:38

标签: c# uwp telerik

我正在跟踪有关如何在uwp应用程序中使用telerik的教程。 This is the link to tutorial.我已按照本教程中的步骤进行操作,但出现了一个似乎不太清楚的错误。

这是我从Visual Studio获得的信息的一部分。

System.ArgumentException: Cannot create dynamic property getter for non-public types.
   at Telerik.Core.DynamicHelper.CreatePropertyValueGetter(Type type, String propertyName)
   at Telerik.UI.Xaml.Controls.Chart.PropertyNameDataPointBinding.GetValue(Object instance)
   at Telerik.UI.Xaml.Controls.Chart.CategoricalSeriesDataSource.InitializeBinding(DataPointBindingEntry binding)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.GenerateDataPoint(Object dataItem, Int32 index)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.BindCore()
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.Bind()
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.Rebind(Boolean itemsSourceChanged, IEnumerable newSource)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeries.OnTemplateApplied()
   at Telerik.UI.Xaml.Controls.RadControl.OnApplyTemplate()
   at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
   at Telerik.UI.Xaml.Controls.RadControl.MeasureOverride(Size availableSize)

以及

Windows.UI.Xaml.UnhandledExceptionEventArgs

MainPage.xaml.cs包含以下代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using TryOutTelerikUI.Models;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
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;

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

namespace TryOutTelerikUI
{
    /// <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();
            this.DataContext = CityManager.GetCities();
        }
    }
}

和MainPage.xaml文件:

<Page
    x:Class="TryOutTelerikUI.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TryOutTelerikUI"
    xmlns:models="using:TryOutTelerikUI.Models"
    xmlns:telerik="using:Telerik.UI.Xaml.Controls.Chart"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <telerik:RadCartesianChart Name="RadChart">
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:CategoricalAxis />
            </telerik:RadCartesianChart.HorizontalAxis>
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis />
            </telerik:RadCartesianChart.VerticalAxis>
            <telerik:LineSeries ItemsSource="{Binding}">
                <telerik:LineSeries.ValueBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="Value"/>
                </telerik:LineSeries.ValueBinding>
                <telerik:LineSeries.CategoryBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="Name"/>
                </telerik:LineSeries.CategoryBinding>
            </telerik:LineSeries>
        </telerik:RadCartesianChart>
    </Grid>
</Page>

应用程序中使用的其他类是: 城市阶级

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

namespace TryOutTelerikUI.Models
{
    class City
    {
        public string Name { get; set; }
        public double Value { get; set; }
    }
}

和城市经理阶层

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

namespace TryOutTelerikUI.Models
{
    class CityManager
    {
        private static Random Random = new Random();
        private static string[] CityNames = new string[] { "Melbourne", "Sydney", "Brisbane", "Adelaide", "Perth" };

        public static List<City> GetCities()
        {
            List<City> cities = new List<City>();

            foreach(var cityName in CityNames) cities.Add(new City() { Name = cityName, Value = Random.Next(50, 100) });

            return cities;
        }
    }
}

错误来自if语句中的代码行中的App.g.i.cs。

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
            };
#endif

1 个答案:

答案 0 :(得分:0)

该错误提供了一些线索,可能是什么原因:

Cannot create dynamic property getter for non-public types.

您可以看到您没有看到CityCityManager类的公共访问修饰符。更改这些,然后重试。有关错误的更多信息,请参见可用的source code