SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
0
0

I have the following code and want to move this portion to code-behind but have problems understanding how I can programmatically set the properties in Style:

<s:SciChartSurface.ChartModifier>

                <!-- Provides Interactivity -->
                <s:RubberBandXyZoomModifier IsAnimated = "False" IsXAxisOnly = "True" ExecuteOn = "MouseRightButton"/>
                <s:ZoomPanModifier XyDirection="XYDirection" ClipModeX = "ClipAtExtents" ExecuteOn ="MouseLeftButton" />
                <s:MouseWheelZoomModifier XyDirection = "XYDirection"/>
                <s:ZoomExtentsModifier IsAnimated = "False" ExecuteOn = "MouseDoubleClick" />
                <s:XAxisDragModifier  DragMode = "Scale"/>
                <s:CursorModifier SourceMode="AllSeries"  UseInterpolation="True"/>

                <!-- Provides selection of series and custom styling to the selected series -->
                <s:SeriesSelectionModifier ReceiveHandledEvents="True" SelectionChanged="SeriesSelectionModifier_OnSelectionChanged">
                    <s:SeriesSelectionModifier.SelectedSeriesStyle>
                        <Style TargetType="s:BaseRenderableSeries">
                            <Setter Property="SeriesColor" Value="White"/>
                            <Setter Property="PointMarkerTemplate">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <s:EllipsePointMarker Fill="#FF00DC" Stroke="White" Width="7" Height="7"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </s:SeriesSelectionModifier.SelectedSeriesStyle>
                </s:SeriesSelectionModifier>

                <!-- Provides a data source for the legend control -->
                <s:LegendModifier ShowLegend="True" GetLegendDataFor="SelectedSeries" Margin="10"/>

            </s:ModifierGroup>
        </s:SciChartSurface.ChartModifier>

Particularly the SeriesSelectionModifier and its property setters seem difficult for me to implement in code-behind. Can you please provide some sample code how I would actually implement the SeriesSelectionModifier with above Property Setters above in C# code rather than in XAML?

Thanks

  • You must to post comments
Best Answer
1
0

Hi Matt,

I would recommend you don’t move this code to code-behind. Working in code-behind with WPF is complex and messy at best, and plain doesn’t work at worst! We don’t provide such examples as to do so would be to give non best-practice examples of how to use SciChart.

If you do wish to go down this route, I would recommend trying one of the following:

Best regards,
Andrew

  • You must to post comments
0
0

Hi Andrew,

Thanks for your prompt answer. What would your recommended route given that I want to create any number of panes dynamically in code-behind and want to attach SeriesSelectedModifiers to specific SciChartSurfaces (I am afraid I am still a little confused about the exact architecture regarding multipane setups…does one SciChartGroup contain multiple SciChartSurfaces and each surface in turn contains any number of renderable series? ). Can I setup SeriesSelectedModifier styles as resource within XAML and access such styles then from within code-behind?

  • Andrew
    SciChartGroup is just an ItemsControl (like ListBox), but has been styled to allow resizing and tabbing of the items. SciChartGroup has one to many ChartPanes. Each ChartPane can have any content you like, its only in our examples we template the chart panes to show a single SciChartSurface per pane.Yes, you can declare styles in resources in XAML and access from code-behind. To use this you would use the third technique I linked to above.Finally, I would recommend if you are building an application with ScichartGroup, following our reference implementation, which is based on MVVM, see 'Create Multi Pane Stock Charts' example. That way, you get the hierarchy of Views matching ViewModels. Is there any reason why you cannot do this in your application?
  • bbmat
    I am looking at the very same example. As I just create my own chart usercontrol, MVVM for such "simple" task seems like going slightly overboard. (I am sure some disagree and implement MVVM even in the smallest projects). Please keep in mind that moving UI logic to code-behind is completely legitimate and I consider functionality and interaction between the main UI control and panes still UI logic. Also, testability is not a problem here as the project is small enough and testable even without MVVM "logic segregation".But I will consider your suggestion. Thanks.
  • Andrew
    Sure, its legitimate, but managing and declaring styles, control templates, bindings, converters etc... in code behind are a real nightmare! If at all possible, I would move these to XAML, even if you use the resource dictionary or XamlReader.Load technique above.
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.