Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

TemplateValuePresenter

Solved!
Go to solution

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

0 Kudos
Message 1 of 2
(5,722 Views)
Solution
Accepted by danxia

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>


TemplateValuePresenter.png


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.##" );
        }
        
        ...
    }

~ Paul H
Message 2 of 2
(5,720 Views)