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

1 vote
9k views

Hi!
Our Designer wants the LineGraphs to continue under the axis and the gridlines area not to have a border, to accomplish some kind of “open” look&feel.
To get this working, i think i need to template the scichartsurface and put the axis over the gridlinesarea.
I did not find any hints on templating the surface itself, only other parts.
In the example styles you only change colors and borders, but not the template itself.

Can you give me some advice? Am i even on the right track?

Thanks,
Claudius

Showing 2 results
This template supports the sidebar's widgets. Add one or use Full Width layout.