我想通過我的CustomNumericLabelProvider訪問viewModel中的縮放因子。自定義標籤提供程序:無法重寫Init()方法
我不太清楚,最好的方法是什麼,但我想如果我用初始化(IAxis不parentAxis)方法,這是在LabelProvider所示,我也許可以通過父軸進行訪問documentation。我試過了,但現在我得到一個錯誤,告訴我「沒有合適的替代方法」。
如果我註釋掉Init()方法,CustomNumericLabelProvider效果很好(具有硬編碼的縮放因子)。
任何想法爲什麼我收到此錯誤消息?或者,在我的viewModel中訪問縮放因子的另一個好方法是什麼?
注意:我也嘗試將viewModel傳遞給標籤提供程序的自定義構造函數(我能夠使用viewportManager做這樣的事情),但是這似乎不起作用。
下面的代碼(通過自定義構造函數,雖然我得到同樣的錯誤信息沒有它)
public class CustomNumericLabelProvider : SciChart.Charting.Visuals.Axes.LabelProviders.NumericLabelProvider
{
// Optional: called when the label provider is attached to the axis
public override void Init(IAxis parentAxis) {
// here you can keep a reference to the axis. We assume there is a 1:1 relation
// between Axis and LabelProviders
base.Init(parentAxis);
}
/// <summary>
/// Formats a label for the axis from the specified data-value passed in
/// </summary>
/// <param name="dataValue">The data-value to format</param>
/// <returns>
/// The formatted label string
/// </returns>
public override string FormatLabel(IComparable dataValue)
{
// Note: Implement as you wish, converting Data-Value to string
var converted = (double)dataValue * .001 //TODO: Use scaling factor from viewModel
return converted.ToString();
// NOTES:
// dataValue is always a double.
// For a NumericAxis this is the double-representation of the data
}
}
我設法繞過這個問題,現在只需創建幾個硬編碼標籤提供程序。這似乎工作正常,但我不知道這是否是正確的方法。 我還需要在每個方法中註釋** Init()**方法。我必須在這裏錯過一些東西。 :) –