03-04-2014 07:01 PM
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");
in WPF, I cant find an equivalent to "MajorDivisions.LabelFormat". Has this capability been removed for the WPF version of the slider control?
Solved! Go to Solution.
03-05-2014 10:22 AM
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>
03-05-2014 10:54 AM
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
03-05-2014 11:18 AM
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.
05-20-2014 04:16 PM
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.
05-20-2014 05:32 PM
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).
05-21-2014 10:29 AM
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.