Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set bindings of range of axes

Hello,I want to set the Maximum of Y-axis by using a viewmodel's property. I found a link at

http://zone.ni.com/reference/en-XX/help/372636F-01/mstudiowebhelp/html/wpfwritablegraphaxescursors/

which used xaml language to set range, but that's not exactly I wanted. Anyone can help me?

0 Kudos
Message 1 of 7
(6,375 Views)

You can bind the Range property like any other dependency property; you just need to expose both the minimum and maximum through a Range<TData> object on your model.


    // Model
    public Range<double> ModelRange { get { ... } }

    // Y-Axis Binding
    <AxisDouble Orientation="Vertical" Range="{Binding ModelRange}" ...

~ Paul H
0 Kudos
Message 2 of 7
(6,369 Views)

The AxisDouble doesn't contain a Source property nor a DataContext property. How can I set  the binding? I set the datacontext in NiGraph control and  tried to use "Range="{Binding ModelRange}"", but it didn't work.

0 Kudos
Message 3 of 7
(6,364 Views)

I see what you mean now; appologies for not trying out a full example in the first place. It looks like the graph is not maintaining the logical tree for child components, which is preventing binding using the inherited data context. I have created a task to fix this.


The simplest workaround available is to expose your model as a resource. This will allow you to use Range="{Binding ModelRange, Source={StaticResource ModelResourceKey}}" to explicitly define the source of the binding.


Here is a full XAML example demonstrating this approach to binding Range on an axis (and how to initialize DataContext for other elements):


    <Grid>
        <Grid.Resources>
            <my:Model x:Key="model" />
        </Grid.Resources>

        <ni:Graph DataContext="{StaticResource model}">
            <ni:Graph.Axes>
                <ni:AxisDouble Range="{Binding ModelRange, Source={StaticResource model}}" />
            </ni:Graph.Axes>
        </ni:Graph>
    </Grid>

~ Paul H
0 Kudos
Message 4 of 7
(6,360 Views)

Yes, that's a good solution.Thanks.

0 Kudos
Message 5 of 7
(6,313 Views)

Just wanted to let you know this issue was fixed in the Measurement Studio 2015 release.

~ Paul H
Message 6 of 7
(4,637 Views)

I have the Range of my AxisDouble binding with my model ok but the RangeCurser.VerticalRange does not.

0 Kudos
Message 7 of 7
(3,740 Views)