Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
190
Is it possible to set Ranges in Style?
posted

I am trying to set Ranges property in Style but it doesn't work.

<ig:LinearGraphRangeCollection x:Key="DefaultLinearGraphRangeCollection">
        <ig:XamLinearGraphRange StartValue="0"
                EndValue="50"
                Brush="#FF990000"/>
        <ig:XamLinearGraphRange StartValue="50"
                EndValue="90"
                Brush="Yellow"/>
        <ig:XamLinearGraphRange StartValue="90"
                EndValue="100"
                Brush="#FF38761D"/>
    ig:LinearGraphRangeCollection>
<Style TargetType="ig:XamLinearGauge">
    <Setter Property="Ranges" Value="{StaticResource DefaultLinearGraphRangeCollection}">Setter>
Style>

If I set the property from code behind it works:

var ranges = FindResource("DefaultLinearGraphRangeCollection");       

xlgr.Ranges = ranges as LinearGraphRangeCollection;

What is the correct way to set predefined Ranges in Style?

Thanks,


Parents
No Data
Reply
  • 34430
    Offline posted

    Hello Alex,

    I have been checking with our development team in this case to see if this is possible, but it appears this is not currently possible with the XamLinearGauge control. The LinearGraphRangeCollection appears to be set locally to a new, empty collection at a point after the styles for the controls are actually evaluated. It likely works from code-behind because this is after that initial evaluation has already finished, and so setting the style locally after this period will apply the Ranges collection.

    As a general rule, though, this likely would not be a great property to set in a Style, as it would cause the LinearGraphRangeCollection would likely become a singleton. This means that if this were to work, the collection would only really take effect on a single gauge.

    Using the code that you have provided and the information provided to me by our development staff (above), I would recommend against trying to set the XamLinearGauge.Ranges property in a Style. Instead, I would recommend that you simply set the Ranges property on your gauge to a StaticResource pointing at the collection that you have defined as a resource. Using the code you have provided, this would look like so:


    <ig:XamLinearGauge Ranges=”{StaticResource DefaultLinearGraphRangeCollection}” />

    I hope this helps. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

Children
No Data