Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Slider - Change ScaleKind programatically in C#

Solved!
Go to solution

How do I go about changing the ScaleKind programatically in C#? The WPF properties look simple enough but I don't see a way to map this to C# as SkaleKind doesn't appear anywhere in the list of "intellisense" options.

 

<ni:SliderDouble...         

  <ni:SliderDouble.Scale>               

    <ni:NumericScale ScaleKind="Linear"/>           

  </ni:SliderDouble.Scale>

 

or           

  <ni:SliderDouble.Scale>               

    <ni:NumericScale ScaleKind="LogarithmBase10"/>           

  </ni:SliderDouble.Scale>

 

 

0 Kudos
Message 1 of 3
(6,731 Views)
Solution
Accepted by FoxGrove

If your XAML is setup like your first example, you can give your NumericScale a name and assign the value directly in code:


    XAML
    <ni:SliderDouble ...>
        <ni:SliderDouble.Scale>
            <ni:NumericScale x:Name="scale" ScaleKind="Linear" />
        </ni:SliderDouble.Scale>
    </ni:SliderDouble>

    Code
    scale.ScaleKind = RangeScaleKind.LogarithmBase10;



If naming the scale is not an option, then you can cast the Scale property on the slider to the appropriate type:


    var scale = (NumericScale)slider.Scale;
    scale.ScaleKind = RangeScaleKind.LogarithmBase10;

~ Paul H
Message 2 of 3
(6,725 Views)

Thanks again Paul! In C# I am now able to do this:

 

((NumericScale)slideDemo.Scale).ScaleKind = m_ScaleKind;

 

 

0 Kudos
Message 3 of 3
(6,722 Views)