Measurement Studio for .NET Languages

取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 7 条)
7,284 次查看

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 项奖励
2 条消息(共 7 条)
7,278 次查看

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 项奖励
3 条消息(共 7 条)
7,273 次查看

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 项奖励
4 条消息(共 7 条)
7,269 次查看

Yes, that's a good solution.Thanks.

0 项奖励
5 条消息(共 7 条)
7,222 次查看

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

~ Paul H
6 条消息(共 7 条)
5,546 次查看

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

0 项奖励
7 条消息(共 7 条)
4,649 次查看