Dogs Chasing Squirrels

A software development blog

Monthly Archives: April 2018

Wrapping the Legend in SciChart

0

I’ve been using SciChart as a real-time graphing control. There’s documentation on the website about how to make the legend wrap when it’s too long but it’s not clear. It seems you can’t do it with LegendModifier alone and while you can do it with SciChartLegend they don’t make it clear where the control is supposed to go.

Anyway, this is what works:

<s:SciChartSurface.ChartModifier>
  <s:ModifierGroup>
    <s:LegendModifier                                     
      x:Name="LegendModifier"
      ShowLegend="True"
      ShowVisibilityCheckboxes="False"
      Orientation="Horizontal"
      Margin="0,10,0,10"
      LegendPlacement="Top" 
      >
      <s:LegendModifier.LegendTemplate>
        <ControlTemplate TargetType="s:LegendPlaceholder">
          <s:SciChartLegend
            Orientation="Horizontal"
            LegendData="{Binding LegendData, ElementName=LegendModifier}" 
            >
            <s:SciChartLegend.ItemsPanel>
              <ItemsPanelTemplate>
                <WrapPanel Orientation="{Binding Orientation, RelativeSource={RelativeSource AncestorType=s:SciChartLegend}}" />
              </ItemsPanelTemplate>
            </s:SciChartLegend.ItemsPanel>
          </s:SciChartLegend>
        </ControlTemplate>
      </s:LegendModifier.LegendTemplate>
    </s:LegendModifier>
  </s:ModifierGroup>
</s:SciChartSurface.ChartModifier>