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

0 votes
983 views

I have a DataTemplate defined in my xaml file that I’d like to access from my ViewModel that I use to manage the layout and look of the chart legend

Here is the DataTemplate I have defined:

<DataTemplate x:Key="CustomLegendTemplate"
                  DataType="s:SeriesInfo">
        <Grid HorizontalAlignment="Right"
              VerticalAlignment="Top"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <!--  Series icon, binds to SeriesInfo.Stroke  -->
            <Ellipse Grid.Column="0"
                     Width="7"
                     Height="7"
                     Margin="2 2 8 0"
                     HorizontalAlignment="Right"
                     VerticalAlignment="Top"
                     Fill="{Binding Stroke,
                                    Converter={StaticResource ColorToBrushConverter}}" />

              <!--Series name (SeriesInfo.SeriesName)-->  
            <TextBlock Grid.Column="1"
                           Width="15"
                           HorizontalAlignment="Right"
                           FontSize="10"
                           Text="{Binding SeriesName}" />

            <!--  Show or hide the 'Visibility Checkboxes'  -->
            <Grid Grid.Column="1"
                  Background="Transparent"
                  Visibility="{Binding DataContext.ShowVisibilityCheckboxes,
                                       ElementName=PART_LegendItems,
                                       Converter={StaticResource BooleanToVisibilityConverter}}">

                <!--  Binds to SeriesInfo.IsVisible to show and hide the series  -->
                <CheckBox Width="16"
                          Height="16"
                          HorizontalAlignment="Right"
                          VerticalAlignment="Top"
                          FontSize="10"
                          Foreground="{Binding Stroke,
                                               Converter={StaticResource ColorToBrushConverter}}"
                          IsChecked="{Binding IsVisible,
                                              Mode=TwoWay}">
                    <CheckBox.LayoutTransform>
                        <ScaleTransform ScaleX="0.7" ScaleY="0.7" />
                    </CheckBox.LayoutTransform>
                </CheckBox>
            </Grid>
        </Grid>
    </DataTemplate>

Now I’d like to access this template from my ViewModel to help manipulate my Legend the ViewModel code I have :

ModifierGroup legendInfo = new ModifierGroup(new LegendModifier()
            {
                ShowLegend = true,
                Orientation = Orientation.Vertical,
                Margin = new Thickness(0, 0, 0, 0),
                LegendPlacement = LegendPlacement.Inside,
                GetLegendDataFor = SourceMode.AllSeries,
                ShowVisibilityCheckboxes = true,
                FontSize = 8,
                Background = (Brush)AxisColor.ConvertFromString("Transparent"),
                ShowSeriesMarkers = true
            });

Then I add this to a ChartModifier = new ModifierGroup(XAxisDrag, YAxisDrag, ZoomExtents, RubberBandZoom, PanModifier, Rollover, legendInfo);

It is all working beautifully, but how can I reach for the xaml DataTemplate I have defined ?

Thank you for the excellent support

0 votes
1k views

Hi,

I am developing an MVVM WPF application and need to access the SelectedPointMarkers property of DataPointSelectionModifier from the ViewModel.

From looking at the DataPointSelectionModifier documentation (https://www.scichart.com/documentation/win/current/webframe.html#DataPoint%20Selection.html) I can see how you can get the X and Y coordinate values of a selected point in a view, by binding the PointMarkersSelectionModifier to a listbox.

However this doesn’t really help me, I need to get the coordinates of the SelectedPointMarker into a property inside the ViewModel that can be accessed, rather than just binding to a listbox in the view itself.

I’ve also looked at this similar post: (https://www.scichart.com/questions/wpf/i-want-to-bind-selectedpointmarkers-of-datapointselectionmodifier), but I had no luck getting Kenishis solution to work in my case.

How can i do this?

Thanks.

1 vote
0 answers
3k views

Hi I tried to bind the ChartModifer to a property in the VM. But though it build successful, and there is no warning or errors when I run the application , but the ChartModifier does not work.

Here is my code

    <sci:SciChartSurface Grid.Row="1" 
                         YAxes="{sci:AxesBinding YAxes}"
                         XAxes="{sci:AxesBinding XAxes}"
                         RenderableSeries="{sci:SeriesBinding RenderableSeries}"
                         Background="{Binding ChartBackBrush}"
                         Foreground="{Binding ChartForeBrush}"
                         ViewportManager="{Binding ViewportManager}"
                         ChartModifier="{Binding ChartModifiers}">
    </sci:SciChartSurface>

In ViewModel, I created all the child for the ChartModifiers. But it does not work.

        ChartModifiers = new ObservableCollection<IChartModifier>();
        //ModifierGroup.ChildModifiers
        ChartModifiers.Add(rubberBandXyZoomModifier);
        ChartModifiers.Add(new ZoomPanModifier()
        {
            ExecuteOn = ExecuteOn.MouseRightButton,
            ClipModeX = SciChart.Charting.ClipMode.None
        });
        ChartModifiers.Add(new ZoomExtentsModifier());
        ChartModifiers.Add(new MouseWheelZoomModifier());
        rolloverModifer = new RolloverModifier()
        {
            ExecuteOn = ExecuteOn.MouseMove,
            ShowTooltipOn = RolloverVisible
        };
        ChartModifiers.Add(rolloverModifer);

        xAxisDrag = new XAxisDragModifier()
        {
            IsEnabled = true,
            ClipModeX = SciChart.Charting.ClipMode.None,
            DragMode = SciChart.Charting.AxisDragModes.Pan
        };
        yAxisDrag = new YAxisDragModifier()
        {
            IsEnabled = true,
            DragMode = SciChart.Charting.AxisDragModes.Pan
        };

        ChartModifiers.Add(xAxisDrag);
        ChartModifiers.Add(yAxisDrag);
Showing 3 results
This template supports the sidebar's widgets. Add one or use Full Width layout.