2017-04-06 1 views
1

내 CustomNumericLabelProvider를 통해 viewModel의 배율 인수에 액세스하려고합니다.Custom Label Provider : Init() 메서드를 재정의 할 수 없습니다.

내가 가장 좋은 방법이 무엇인지 확실히 모르겠지만, 내가 LabelProvider에 표시 된 초기화 (IAxis parentAxis) 방법을 사용하면 내가 부모 축을 통해 액세스 할 수 있습니다 생각 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 
    } 
} 
+0

필자는 하드 코딩 된 여러 개의 레이블 제공 업체를 생성하여이 문제를 즉시 해결할 수있었습니다. 이것은 잘 작동하는 것 같지만 올바른 접근 방법인지는 확실치 않습니다. 또한 각각의 ** Init() ** 메소드를 주석 처리해야했습니다. 여기에 뭔가 빠져 있어야합니다. :) –

답변

1

나는 당신의 ViewModel에를 CustomNumericLabelProvider의 생성자에 배율 인수를 전달하고 인스턴스화 제안 할 것 .

그래서 코드는

public class CustomNumericLabelProvider : LabelProviderBase 
    { 
     private readonly double _scaleFactor; 

     public CustomNumericLabelProvider(double scaleFactor) 
     { 
      _scaleFactor = scaleFactor; 
     } 

     public override string FormatLabel(IComparable dataValue) 
     { 
      // TODO 
     } 

     public override string FormatCursorLabel(IComparable dataValue) 
     { 
      // TODO 
     } 
    } 

    public class MyViewModel : ViewModelBase 
    { 
     private CustomNumericLabelProvider _labelProvider = new CustomNumericLabelProvider(0.01); 

     public CustomNumericLabelProvider LabelProvider { get { return _labelProvider; } } 
    } 

가되어 NumericAxis의 데이터 컨텍스트 당신의 ViewModel입니다 가정

<s:NumericAxis LabelProvider="{Binding LabelProvider}"/> 

을 다음과 같이 그런 다음에 바인딩합니다.

SciChart v5에는 ViewModel에서 동적으로 축을 생성하기위한 AxisBindings (SeriesBinding과 유사)에 대한 새로운 API가 제공 될 것입니다. 이것은 MVVM의 동적 축을 훨씬 쉽게 만듭니다. 우리의 WPF Chart Examples here에 액세스하여 SciChart v5를 시운전에 사용할 수 있습니다.

+1

나는 비슷한 시도를했지만 작동에 문제가있었습니다. 그것이 다행 한 해결책이라고 생각합니다. 나는 오늘 그것을 볼 것입니다. 답변 해주셔서 감사합니다! –

관련 문제