Pre loader

Setting value in RenderableSeriesViewModel

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

I’m trying to set a property value from a property in my custom extension of BaseRenderableSeriesViewModel. Looking at the documentation, it seems this is what I need:

BaseRenderableSeriesViewModel.SetValue()

But I’m a little confused as to what it needs as an input, what exactly is the “ref Property”? Here’s what I’ve tried:

public class CustomEnumRenderableSeriesViewModel : BaseRenderableSeriesViewModel
{
    private float startY;
    public float StartY
    {
        get { return startY; }
        set {
            SetValue<float>(ref startY, value, "StartY");
        }
    }


    // Tell SciChart what type of RenderableSeries you want to instantiate
    public override Type RenderSeriesType
    {
        get { return typeof(CustomEnumRenderableSeries); }
    }
}

public sealed class CustomEnumRenderableSeries : CustomRenderableSeries
{
    public float StartY
    {
        get { return (float)GetValue(StartYProperty); }
        set { SetValue(StartYProperty, value); }
    }
    public static readonly DependencyProperty StartYProperty =
        DependencyProperty.Register("StartY", typeof(float), typeof(CustomEnumRenderableSeries), new PropertyMetadata(0f));
    ....

but the CustomEnumRenderableSeries’s StartY isn’t getting set. I’m not exactly sure what the Type T parameter should be. Is it the type of the property (float in this case) like I have? What then is the property reference I should be passing?

  • You must to post comments
1
0

Have you put a breakpoint on CustomEnumRenderableSeriesViewModel.StartY getter and setter to see if it is being hit?

If not, it could be your binding from CustomEnumRenderableSeries.StartY to CustomEnumRenderableSeriesViewModel.StartY is not set, or is set incorrectly.

From our Documentation: Worked Example – CustomRenderableSeries in MVVM

Finally, apply the SeriesBinding and any style. It is imperative to
base any style on MvvmDefaultRenderableSeries style, or the series
will not show. To do this, in your View you will need a
resource-dictionary and to pull in the SciChart default styles:

<UserControl.Resources>               

   <ResourceDictionary>

      <!-- Merged Dictionary is required for BasedOn attribute -->
      <ResourceDictionary.MergedDictionaries>
         <ResourceDictionary Source="/SciChart.Charting;component/Themes/Default.xaml"/>
      </ResourceDictionary.MergedDictionaries>

      <!-- The style for the custom renderable series -->
      <!-- IMPORTANT! BasedOn must equal MvvmDefaultRenderableSeriesStyle to
      <!-- pick up the defaults -->
      <Style TargetType="local:SplineLineRenderableSeries" x:Key="splineSeriesStyle"
               BasedOn="{StaticResource MvvmDefaultRenderableSeriesStyle}">
         <Setter Property="IsSplineEnabled" Value="True"/>
         <Setter Property="UpSampleFactor" Value="10"/>
         <Setter Property="Stroke" Value="DarkGreen"/>
         <Setter Property="StrokeThickness" Value="2"/>
         <Setter Property="PointMarkerTemplate">
            <Setter.Value>
               <ControlTemplate>
                  <s:EllipsePointMarker Fill="White" Stroke="DarkGreen"/>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>

   </ResourceDictionary>       

</UserControl.Resources>

Notice the style declared and bindings between Custom series and Custom series ViewModel.

does that help?

  • You must to post comments
0
0

Thanks for the reply, yes I’ve placed a breakpoint in the setter of the view model (line 8) and the setter of the series (line 25) and it hits the first, but not the second.

I’ve got a style in my generic.xaml, and have experimented with setting values in there. Here, the value in the series is set:

   .. in MergedDictionaries
    <ResourceDictionary Source="/SciChart.Charting;component/Themes/Default.xaml"/>
   ...

<Style TargetType="helpers:CustomEnumRenderableSeries"
       BasedOn="{StaticResource MvvmDefaultRenderableSeriesStyle}">
      <Setter Property="StartY" Value="0.2"/>
</Style>

And the series is displaying fine, so I think it’s linking the ViewModel with the RenderableSeries okay?

I’ll try make a small comparable test program.

Edit: It only took 5 minutes to add my custom series to a small project, so I’ve attached it demonstrating the style setting the value to 0.2, and the ViewModel failing to set it to 0.5.

Attachments
  • Andrew Burnett-Thompson
    Oh the setter of the StartY in the CustomEnumRenderableSeries will not be called by the WPF Binding engine. Instead, you can setup a PropertyChanged callback in your dependency property registration. For more info see http://stackoverflow.com/questions/9212583/dependencyproperty-not-triggered
  • Ken Hobbs
    Good thinking! But it’s still not picking up the 0.5 (does now get triggered for the style setting it to 0.2 though). I’ve moved the breakpoint to there in the attached project and added a console output to keep track.
  • Ken Hobbs
    Did you get a chance to run the solution? Still having problems getting it to work, even using the PropertyChanged callback.
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies