- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个名为 ShellViewModel 的类和一个名为 Shell.xaml 的 WPF 页面。在我的 ShellViewModel 中,我有一个函数可以从 .csv 文件读取数据并将数据显示到 Shell.xaml 中的数据网格中。数据在图表上绘制为线图。
文件读取正常,数据在数据网格上正确显示。数据结构有 25 列。第一列是数据的名称,接下来的 24 列是数据点。虽然数据在数据网格中正确显示,但图形中没有数据点。
这是我的图表的代码。我得到的错误是“
System.ArgumentException: 'Value' property was already registered by 'Point'"
注意:obsLoadForecasts 存储了显示在数据网格中的数据
图表的 ShellViewModel.cs 代码:
public void UpdateLoadChart()
{
var forecastList = obsLoadForecasts.ToList();
var dataList = new List<ForecastPoint>();
forecastList.Where(a => a.ObsForecast.ZoneName == zoneName).ToList().ForEach(a =>
{
dataList.Add(new ForecastPoint(1, a.ObsForecast.Hr1));
dataList.Add(new ForecastPoint(2, a.ObsForecast.Hr2));
dataList.Add(new ForecastPoint(3, a.ObsForecast.Hr3));
dataList.Add(new ForecastPoint(4, a.ObsForecast.Hr4));
dataList.Add(new ForecastPoint(5, a.ObsForecast.Hr5));
dataList.Add(new ForecastPoint(6, a.ObsForecast.Hr6));
dataList.Add(new ForecastPoint(7, a.ObsForecast.Hr7));
dataList.Add(new ForecastPoint(8, a.ObsForecast.Hr8));
dataList.Add(new ForecastPoint(9, a.ObsForecast.Hr9));
dataList.Add(new ForecastPoint(10, a.ObsForecast.Hr10));
dataList.Add(new ForecastPoint(11, a.ObsForecast.Hr11));
dataList.Add(new ForecastPoint(12, a.ObsForecast.Hr12));
dataList.Add(new ForecastPoint(13, a.ObsForecast.Hr13));
dataList.Add(new ForecastPoint(14, a.ObsForecast.Hr14));
dataList.Add(new ForecastPoint(15, a.ObsForecast.Hr15));
dataList.Add(new ForecastPoint(16, a.ObsForecast.Hr16));
dataList.Add(new ForecastPoint(17, a.ObsForecast.Hr17));
dataList.Add(new ForecastPoint(18, a.ObsForecast.Hr18));
dataList.Add(new ForecastPoint(19, a.ObsForecast.Hr19));
dataList.Add(new ForecastPoint(20, a.ObsForecast.Hr20));
dataList.Add(new ForecastPoint(21, a.ObsForecast.Hr21));
dataList.Add(new ForecastPoint(22, a.ObsForecast.Hr22));
dataList.Add(new ForecastPoint(23, a.ObsForecast.Hr23));
dataList.Add(new ForecastPoint(24, a.ObsForecast.Hr24));
});
ObsLoadChartData = dataList;
RaisePropertyChanged("ObsLoadChartData");
if (!(obsLoadForecasts.Exists(a => a.ObsForecast.ZoneName.Contains("Interchange"))))
{
try
{
//Peak Load Forecast values defined
maxRTOvalue = dataList.Max(ForecastPoint => ForecastPoint.Value);
maxRTOhour = dataList.FindIndex(ForecastPoint => ForecastPoint.Value == maxRTOvalue);
maxRTOhour = maxRTOhour + 1;
}
catch
{
Log("Unable to determine Peak Load Forecast ");
maxRTOvalue = 0;
maxRTOhour = 0;
maxRTOhour = 0;
}
}
}
public class ForecastPoint : DependencyObject
{
public ForecastPoint(int hour, decimal value)
{
Hour = hour;
Value = value;
}
public static readonly DependencyProperty _hour = DependencyProperty.Register("Hour", typeof(Int32), typeof(ForecastPoint));
public Int32 Hour
{
get { return (int)GetValue(_hour); }
set { SetValue(_hour, value); }
}
public static readonly DependencyProperty _value = DependencyProperty.Register("Value", typeof(decimal), typeof(Point));
public decimal Value
{
get { return (decimal)GetValue(_value); }
set { SetValue(_value, value); }
}
}
Shell.xaml 中的代码:
<me:LoadChart x:Name="MyLoadChart" SnapsToDevicePixels="True" />
我的 LoadChart.xaml 中的代码:
<UserControl x:Class="ProbeCTO.LoadChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:chartingPrimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:me="clr-namespace:ProbeCTO"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style TargetType="{x:Type charting:Chart}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type charting:Chart}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<datavis:Title Content="{TemplateBinding Title}" HorizontalAlignment="Left" Margin="20 0" FontWeight="Bold" Foreground="{StaticResource DefaultButtonBrush}" Style="{TemplateBinding TitleStyle}" />
<!-- Use a nested Grid to avoid possible clipping behavior resulting from ColumnSpan+Width=Auto -->
<Grid Grid.Row="1" Margin="0,15,0,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<chartingPrimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
<Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
<Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1 0 0 1" />
</chartingPrimitives:EdgePanel>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<charting:Chart x:Name="MyChart" Title="{Binding ObsSelectedLoadForecast.ObsForecast.ZoneName, TargetNullValue=RTO, FallbackValue=RTO}" Grid.Row="1" SnapsToDevicePixels="True" Foreground="#DDD" BorderThickness="0">
<charting:Chart.PlotAreaStyle>
<Style TargetType="{x:Type Grid}">
<Setter Property="Background" Value="{x:Null}" />
</Style>
</charting:Chart.PlotAreaStyle>
<charting:Chart.Axes>
<charting:LinearAxis Orientation="X" ShowGridLines="False" Interval="1" />
<charting:LinearAxis Orientation="Y" ShowGridLines="False" />
</charting:Chart.Axes>
<charting:Chart.Series>
<charting:AreaSeries ItemsSource="{Binding ObsLoadChartData}"
IndependentValuePath="Hour"
DependentValuePath="Value">
</charting:AreaSeries>
<charting:LineSeries ItemsSource="{Binding ObsLoadChartData}"
IndependentValuePath="Hour"
DependentValuePath="Value">
</charting:LineSeries>
</charting:Chart.Series>
</charting:Chart>
</Grid>
最佳答案
简单:您向 DependencyProperty.Register
传递了错误的参数。由于复制和粘贴,我每周做两次。
public static readonly DependencyProperty _value =
DependencyProperty.Register("Value",
typeof(decimal),
typeof(ForecastPoint));
最后一个参数是您代码段中的 typeof(Point)
,但它必须是 typeof(ForecastPoint)
—— 声明类的类型,因为它是在上面的几行中注册 Hour
属性。
顺便说一下,我会将这些命名为 ValueProperty
和 HourProperty
而不是 _value
和 _hour
。这是惯例,也是人们期望看到的。任何试图调用 obj.SetValue(ForecastPoint.ValueProperty, value)
的人都会遇到一些不必要的小麻烦。
关于c# - 系统参数异常 : 'Value' property was already registered by 'Point' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37258396/
问题很简单:我正在寻找一种优雅的使用方式 CompletableFuture#exceptionally与 CompletableFuture#supplyAsync 一起.这是行不通的: priva
对于 Web 服务,我们通常使用 maven-jaxb2-plugin 生成 java bean,并在 Spring 中使用 JAXB2 编码。我想知道如何处理 WSDL/XSD 中声明的(SOAP-
这个问题已经有答案了: Array index out of bound behavior (10 个回答) 已关闭 8 年前。 我对下面的 C 代码感到好奇 int main(){
当在类的开头使用上下文和资源初始化 MediaPlayer 对象时,它会抛出 NullPointer 异常,但是当在类的开头声明它时(因此它是 null),然后以相同的方式初始化它在onCreate方
嘿 我尝试将 java 程序连接到 REST API。 使用相同的代码部分,我在 Java 6 中遇到了 Java 异常,并且在 Java 8 中运行良好。 环境相同: 信任 机器 unix 用户 代
我正在尝试使用 Flume 和 Hive 进行 Twitter 分析。为了从 twitter 获取推文,我在 flume.conf 文件中设置了所有必需的参数(consumerKey、consumer
我在 JavaFX 异常方面遇到一些问题。我的项目在我的 Eclipse 中运行,但现在我的 friend 也尝试访问该项目。我们已共享并直接保存到保管箱文件夹中。但他根本无法让它发挥作用。他在控制台
假设我使用 blur() 事件验证了电子邮件 ID,我正在这样做: $('#email').blur(function(){ //make ajax call , check if dupli
我这样做是为了从 C 代码调用非托管函数。 pCallback 是一个函数指针,因此在托管端是一个委托(delegate)。 [DllImport("MyDLL.dll")] public stati
为什么这段代码是正确的: try { } catch(ArrayOutOfBoundsException e) {} 这是错误的: try { } catch(IOException e) {} 这段
我遇到了以下问题:有导出函数的DLL。 代码示例如下:[动态链接库] __declspec(dllexport) int openDevice(int,void**) [应用] 开发者.h: __de
从其他线程,我知道我们不应该在析构函数中抛出异常!但是对于下面的例子,它确实有效。这是否意味着我们只能在一个实例的析构函数中抛出异常?我们应该如何理解这个代码示例! #include using n
为什么需要异常 引出 public static void main(String[
1. Java的异常机制 Throwable类是Java异常类型的顶层父类,一个对象只有是 Throwable 类的(直接或者间接)实例,他才是一个异常对象,才能被异常处理机制识别。JDK中内
我是 Python 的新手,我对某种异常方法的实现有疑问。这是代码(缩写): class OurException(Exception): """User defined Exception"
我已经创建了以下模式来表示用户和一组线程之间的关联,这些线程按他们的最后一条消息排序(用户已经阅读了哪些线程,哪些没有): CREATE TABLE table(user_id bigint, mes
我正在使用 Python 编写一个简单的自动化脚本,它可能会在多个位置引发异常。在他们每个人中,我都想记录一条特定的消息并退出程序。为此,我在捕获异常并处理它(执行特定的日志记录操作等)后引发 Sys
谁能解释一下为什么这会导致错误: let xs = [| "Mary"; "Mungo"; "Midge" |] Array.iter printfn xs 虽然不是这样: Array.iter pr
在我使用 Play! 的网站上,我有一个管理部分。所有 Admin Controller 都有一个 @With 和一个 @Check 注释。 断开连接后,一切正常。连接后,每次加载页面(任何页面,无论
我尝试连接到 azure 表存储并添加一个对象。它在本地主机上工作得很好,但是在我使用的服务器上我得到以下异常及其内部异常: Exception of type 'Microsoft.Wind
我是一名优秀的程序员,十分优秀!