Pre loader

Tag: ChartModifier MVVM

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 votes
3k 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
6k 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.

Showing 2 results

Try SciChart Today

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

Start TrialCase Studies