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
1

Hi

Based on some window’s size logic I want an ItemTemplateSelector to set the correct ItemTemplate.
But it doesn’t seem like the SciCharLegend picks up the ItemTemplateSelector, because whatever I put into the ItemTemplates it is totally ignored and only the default is rendered.

public class SciChartLegendTemplateSelector : DataTemplateSelector
{
    public DataTemplate NormalItemTemplate { get; set; }
    public DataTemplate SmallItemTemplate { get; set; }

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        return NormalItemTemplate;
    }
}

<DataTemplate x:Key="SciChartLegendNormalItemTemplate">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="NORMAL"></TextBlock>
    </StackPanel>
</DataTemplate>
<DataTemplate x:Key="SciChartLegendSmallItemTemplate">
    <StackPanel Orientation="Vertical">
        <TextBlock Text="SMALL"></TextBlock>
    </StackPanel>
</DataTemplate>
<templateSelectors:SciChartLegendTemplateSelector x:Key="SciChartLegendTemplateSelector"
                                                  NormalItemTemplate="{StaticResource SciChartLegendNormalItemTemplate}"
                                                  SmallItemTemplate="{StaticResource SciChartLegendSmallItemTemplate}"/>

<s:SciChartLegend x:Name="legendControl"
                  s:ThemeManager.Theme="BrightSpark"
                  VerticalAlignment="Bottom"
                  HorizontalAlignment="Stretch"
                  Background="White"
                  FontSize="10"
                  FontStretch="UltraCondensed"
                  LegendData="{Binding LegendData,
                                       ElementName=legendModifier,
                                       Mode=OneWay}"
                  ShowVisibilityCheckboxes="True"
                  ItemTemplateSelector="{StaticResource SciChartLegendTemplateSelector}">
Images
  • You must to post comments
Best Answer
1
0

In order for the SciChartLegend to pick up and use the ItemTemplateSelector you need to explicitly set the SciChartLegend’s ItemTemplate to null in codebehind.

  • Sander Struijk
    This is probably something that should be changed in a future version, as the default behavior should be to use the ItemTemplateSelector over the ItemTemplate if set.
  • You must to post comments
0
0

Hi, I created a small sample to reproduce this bug.

MultipleLinesView.xaml

<UserControl x:Class="Test.MultipleLinesView" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:SciChart="http://schemas.abtsoftware.co.uk/scichart" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           xmlns:test="clr-namespace:Test"
           Loaded="MultipleLinesView_OnLoaded" d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d">

  <UserControl.Resources>
      <DataTemplate x:Key="XySeriesInfoItemTemplate">
          <TextBlock Text="XySeriesInfo"></TextBlock>
      </DataTemplate>
      <DataTemplate x:Key="BandSeriesInfoItemTemplate">
          <TextBlock Text="BandSeriesInfo"></TextBlock>
      </DataTemplate>
      <test:SciChartLegendItemTemplateSelector 
          x:Key="SciChartLegendItemTemplateSelector" 
          XySeriesInfoItemTemplate="{StaticResource XySeriesInfoItemTemplate}"
          BandSeriesInfoItemTemplate="{StaticResource BandSeriesInfoItemTemplate}"/>
  </UserControl.Resources>

  <Grid SciChart:ThemeManager.Theme="ExpressionLight">
      <Grid.RowDefinitions>
          <RowDefinition Height="32"/>
          <RowDefinition Height="*"/>
      </Grid.RowDefinitions>

      <StackPanel Orientation="Horizontal">
          <TextBlock Margin="5" Foreground="#EEE" Text="Get Legend Data For: "/>
          <ComboBox x:Name="cboGetLegendFor" SelectionChanged="CboGetLegendFor_OnSelectionChanged"/>
          <CheckBox x:Name="chkbShowSeries" Content="Show Checkboxes for VisibleSeries" IsChecked="True"/>
      </StackPanel>

      <SciChart:SciChartSurface x:Name="sciChart" Grid.Row="1">

          <!--  Declare RenderableSeries  -->
          <SciChart:SciChartSurface.RenderableSeries>
              <SciChart:FastLineRenderableSeries SeriesColor="#279B27"/>
              <SciChart:FastLineRenderableSeries SeriesColor="#FF1919"/>
              <SciChart:FastLineRenderableSeries SeriesColor="#1964FF"/>
          </SciChart:SciChartSurface.RenderableSeries>

          <!--  Declare Axes  -->
          <SciChart:SciChartSurface.XAxis>
              <SciChart:NumericAxis VisibleRange="0, 60"/>
          </SciChart:SciChartSurface.XAxis>

          <SciChart:SciChartSurface.YAxis>
              <SciChart:NumericAxis VisibleRange="0, 200000"/>
          </SciChart:SciChartSurface.YAxis>

          <!--  Declare ChartModifiers  -->
          <SciChart:SciChartSurface.ChartModifier>
              <SciChart:ModifierGroup>
                  <SciChart:LegendModifier x:Name="legendModifier" 
                                           GetLegendDataFor="AllSeries"/>
                  <SciChart:RolloverModifier DrawVerticalLine="True" 
                                             ShowTooltipOn="Always" 
                                             SourceMode="AllVisibleSeries"/>
              </SciChart:ModifierGroup>
          </SciChart:SciChartSurface.ChartModifier>

      </SciChart:SciChartSurface>

      <SciChart:SciChartLegend x:Name="legendControl"
           Grid.Row="1"
           SciChart:ThemeManager.Theme="{Binding Path=(SciChart:ThemeManager.Theme), 
           RelativeSource={RelativeSource AncestorType=Grid}}"
           Margin="23,23"
           LegendData="{Binding LegendData,
                                ElementName=legendModifier,
                                Mode=OneWay}"
           ShowVisibilityCheckboxes="{Binding IsChecked,
                                              ElementName=chkbShowSeries}"
           ItemTemplateSelector="{StaticResource SciChartLegendItemTemplateSelector}">

      </SciChart:SciChartLegend>

  </Grid>

</UserControl>

MultipleLinesView.xaml.cs

public partial class MultipleLinesView : UserControl
{
    public MultipleLinesView()
    {
        InitializeComponent();

        cboGetLegendFor.Items.Add(SourceMode.AllSeries);
        cboGetLegendFor.Items.Add(SourceMode.AllVisibleSeries);

        cboGetLegendFor.SelectedItem = SourceMode.AllSeries;
    }

    private void MultipleLinesView_OnLoaded(object sender, RoutedEventArgs e)
    {
        // Add some data series of type X=double, Y=double
        var dataSeries0 = new XyDataSeries<int, int> { SeriesName = "Curve A" };
        var dataSeries1 = new XyDataSeries<int, int> { SeriesName = "Curve B" };
        var dataSeries2 = new XyDataSeries<int, int> { SeriesName = "Curve C" };

        var data1 = DataManager.Instance.GetStraightLine(1000, 1.0, 60);
        var data2 = DataManager.Instance.GetStraightLine(2000, 1.0, 60);
        var data3 = DataManager.Instance.GetStraightLine(3000, 1.0, 60);

        // Append data to series.
        dataSeries0.Append(data1.XData, data1.YData);
        dataSeries1.Append(data2.XData, data2.YData);
        dataSeries2.Append(data3.XData, data3.YData);

        sciChart.RenderableSeries[0].DataSeries = dataSeries0;
        sciChart.RenderableSeries[1].DataSeries = dataSeries1;
        sciChart.RenderableSeries[2].DataSeries = dataSeries2;

        // Zoom to extents of the data
        sciChart.ZoomExtents();
    }

    private void CboGetLegendFor_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (legendModifier != null)
        {
            legendModifier.GetLegendDataFor = (SourceMode)cboGetLegendFor.SelectedItem;
        }
    }
}

Here you can see a screenshot of the result

screenshot

Clearly you can see here that the template returned by the ItemTemplateSelector is not used.

  • Andrew
    Hi Sander, thank you for your feedback and sample to reproduce - we have logged a bug on our side and someone will investigate it soon.
  • Sander Struijk
    Thanks Andrew, great help! :)
  • You must to post comments
0
0

Hi Sander,

Thank you for the sample. We investigated the code and found out that the issue appeared to be not an issue at all 🙂 Actually, the reason is that we use a custom DataTemplateSelector for tooltips which works in both Silverlight and WPF. But it is derived from the ContentControl so isn’t applicable in the case of ItemsControl. So you need to state the namespace explicitly:

public class SciChartLegendTemplateSelector : System.Windows.Controls.DataTemplateSelector
{…}

UPDATE:
Please, try setting ItemTemplate to “Null”, because the default one prevents the selector from being called.

Hope this helps!

  • Sander Struijk
    Thanks I will test this out. :)
  • Sander Struijk
    I'm confusedHow is thisusing System.Windows; using System.Windows.Controls;namespace Test { public class SciChartLegendItemTemplateSelector : DataTemplateSelector {...} } different fromusing System.Windows;namespace Test { public class SciChartLegendItemTemplateSelector : System.Windows.Controls.DataTemplateSelector {...} } I tried using the Abt.Controls.SciChart.DataTemplateSelector but the type is not accepted, by the SciCharLegend.ItemTemplateSelector
    • Guest
    • 4 years ago
    • 1
    I'm sorry I havent made this clear, you probably need to set the ItemTemplate property to "Null" also to override the default value.
  • Sander Struijk
    You are correctpublic partial class ConfigurableSignalTrackView : UserControl { public ConfigurableSignalTrackView() { InitializeComponent(); legendControl.ItemTemplate = null; } } legendControl.ItemTemplate = null; made it work, so that was the solution not the explicit namespace reference.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.