09-10-2012 08:41 AM
I want to show my x axis in a different scale than what is actually being used to plot my data (converting MHz to time). It looks like TemplateValuePresenter is what I need but I can't find any documentation on it. I can get this to work by using 2 axes and hiding one of them but I feel like this is a bit of a hack solution. Is there any documentation on TemplateValuePresenter? Specifically I want to know how to access the x axis value in the DataTemplate.
Thanks!
Dan
Solved! Go to Solution.
09-10-2012 10:27 AM
TemplateValuePresenter derives from ValuePresenter, so you can use it anywhere a ValuePresenter is needed, such as the LabelPresenter property on the MajorDivisions of an axis:
<ni:RangeLabeledDivisions>
<ni:RangeLabeledDivisions.LabelPresenter>
<ni:TemplateValuePresenter>
<ni:TemplateValuePresenter.Template>
<DataTemplate>
<TextBlock Text="{Binding}" Padding="8,0" Background="LightGray" />
</DataTemplate>
</ni:TemplateValuePresenter.Template>
</ni:TemplateValuePresenter>
</ni:RangeLabeledDivisions.LabelPresenter>
</ni:RangeLabeledDivisions>
The division value is passed in as the data context, so you can use {Binding} to access it (this is also how the ContentTemplate on content controls works in WPF). To convert between time and MHz, you could pass a custom converter to the binding.
Alternatively, you could derive from ValuePresenter or one of its children yourself, and put the conversion logic there:
public class CustomValueFormatter : ValueFormatter {
protected override string FormatCore<TData>( TData value, ValuePresenterArgs args ) {
double valueInMHz = (double)(object)value;
double result = ConvertToTime( valueInMHz );
return result.ToString( "0.##" );
}
...
}