属性 设置轴的标签位置时出现只读错误 - Infragistics

Property read only error when setting the label location for the axes - Infragistics

我在后面的代码中构建 xamdatachart 轴,如下所示:

NumericYAxis yAxis = new NumericYAxis() { IsInverted=true, MajorStrokeThickness= 0 }; 
NumericYAxis yAxis_right = new NumericYAxis() { IsInverted = false, MajorStrokeThickness = 0 }; 

要将 yAxis 的位置设置为 OutsideLeft 并将 yAxis_right 的位置设置为 OutsideRight,我添加了以下部分:

yAxis.MinimumValue = 0;
yAxis.Title = "Depth";
yAxis.LabelSettings.Location = AxisLabelsLocation.OutsideLeft;

yAxis_right.MinimumValue = 0;
yAxis_right.Title = "Net Production";
yAxis_right.LabelSettings.Location = AxisLabelsLocation.OutsideRight;

但出现错误

"Cannot set a property on object 'Infragistics.Controls.Charts.AxisLabelSettings' because it is in a read-only state."

对它发生的原因有什么见解吗?

我从他们的网站上发现 this link 很有用,我也照做了,但我遇到了上述错误。

引发错误是因为 LabelSettings 中的某些 属性 是只读的,也就是只读的 属性。从你的代码中,只有 Location 属性 被分配,所以我相信 属性 没有 public 设置,当你尝试时会导致错误。

我搜索了 NumericYAxis class 并找到了这个:

http://help.infragistics.com/Help/Doc/wpf/2012.1/clr4.0/html/InfragisticsWPF4.Controls.Charts.XamDataChart.v12.1~Infragistics.Controls.Charts.AxisLabelSettings~LocationProperty.html

所以 Location 既是依赖项 属性(这是静态只读的),也是成员的名称 属性(使用 get 和 set)。当您键入 yAxis_right.LabelSettings.Location 时,只有一个建议出现在 Visual Studio?

显然这是 Xamdatachart 中的一个已知问题。 这是 Infragistics 对此的回应和解决方法。

这主要是由于 AxisLabelSettings 对象被冻结,因此它被置于只读状态。此问题的解决方法是创建一个新的 AxisLabelSettings 对象并将其分配给坐标区的 LabelSettings 属性。您可以为此使用以下代码:

AxisLabelSettings settings = new AxisLabelSettings() { Location = AxisLabelsLocation.OutsideRight };
yAxis.LabelSettings = settings;