Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF slider - How do I change the format of the values in the scale to Hex or other?

Solved!
Go to solution

In the non-WPF version of the slider control I could change the displayed scale format to different styles of values. In this case, I would switch the displayed values to Hex.

 

slideIccMax.MajorDivisions.LabelFormat = newFormatString(FormatStringMode.Numeric, "X4");

 

OldSliderHex.PNG

 

in WPF, I cant find an equivalent to "MajorDivisions.LabelFormat". Has this capability been removed for the WPF version of the slider control?

0 Kudos
Message 1 of 7
(7,146 Views)
Solution
Accepted by topic author FoxGrove

Display of labels is controlled by the LabelPresenter property on the MajorDivisions of the numeric scale:


    <ni:SliderInt32 Range="1, 16383, System.Int32">
        <ni:SliderInt32.Scale>
            <ni:NumericScale>
                <ni:NumericScale.MajorDivisions>
                    <ni:RangeLabeledDivisions LabelPresenter="X4" />
                </ni:NumericScale.MajorDivisions>
            </ni:NumericScale>
        </ni:SliderInt32.Scale>
    </ni:SliderInt32>

~ Paul H
Message 2 of 7
(7,128 Views)

Paul - Thanks! That will work!

 

One more question is how would you change that through code (like C# or VB)? The NI help is very sparse on how you work with the LabelPresenter or MajorDivisions. 

 

 

Chris

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

You can use any type derived from ValuePresenter. By default, we use a GeneralValueFormatter, which takes .NET format strings like X4. So in code:


    majorDivisions.LabelPresenter = new GeneralValueFormatter( "X4" );


I have created a task to update the documentation.

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

I saw this thread when looking for an approach to one of my tasks.

 

I have an app using the WPF graph which has a menu option to change the axis units between Inch and Millimeter. 

 

 

I tried to use the "in code" option as shown in the above response set the LabelPresenter when the user changes the menu setting. However, whenever I get to the statement to set the LabelPresenter, I keep getting this exception:

 

"Cannot set a property on object 'NationalInstruments.Controls.RangeLabeledDivisions' because it is in a read-only state."

 

And a QuickWatch of the full set of properties show the "IsFrozen" property set to "true".

 

 

 

I am trying to avoid having to go through a process to have to convert the complete dataset of actual plotted values, and just change the axis labels.

 

 

Any insight would be helpful.

 

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

For scales, the default values of properties like MajorDivisions are set to frozen values that are shared across all scales (if the values were not frozen, then assigning a label presenter on the default value would change every scale in every control).


To avoid the error, all you need to do is assign a unique instance once to the axis you want to modify. You can set this once in code or in XAML (e.g. axis.MajorDivisions = new RangeLabeledDivisions() in the constructor, or declaring the axis with an empty <RangeLabeledDivisions/> XAML child element).

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

Thanks Paul. 

 

I used the empty <RangeLabeledDivisions/> XAML child element, and am changing the LabelPresenter in the dependency property for the selected axis dimension.  This is working perfectly.

 

 

0 Kudos
Message 7 of 7
(6,855 Views)