Dogs Chasing Squirrels

A software development blog

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>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: