SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Answered
1
0

I am trying to change the background color to match the background of the SciChartSurface but it just doesn’t want to change colors. I have a property bound to enable and disable the legend and that works fine. I tried doing the same for the “Background” property for SciChartLegend but nothing works. Even hard coding a brush doesn’t work. What am I missing?

I am using SciChart v3.42.0.6778

SciChartSurface instantiation in XAML. I am using the BrightSpark default theme.

<s:SciChartSurface Name="SciChartSurface"
Grid.Row="0"
Background="{Binding BackgroundColor, Converter={StaticResource ColorToSolidColorBrushConverter}}"
ChartTitle="{Binding GraphTitle}"
SeriesSource="{Binding GraphRenderModels}"
s:ThemeManager.Theme="BrightSpark">

Modifiers

<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
    <s:RubberBandXyZoomModifier IsAnimated="True"
                                IsEnabled="True"
                                IsXAxisOnly="False"
                                RubberBandFill="#99AAAAAA"
                                ZoomExtentsY="False" />
    <s:ZoomPanModifier ExecuteOn="MouseMiddleButton" IsEnabled="True" />
    <s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick"
                           IsEnabled="True"
                           XyDirection="XDirection" />
    <s:MouseWheelZoomModifier IsEnabled="True" XyDirection="YDirection" />
    <s:YAxisDragModifier AxisId="LeftAxis" />
    <s:YAxisDragModifier AxisId="RightAxis" />
    <s:XAxisDragModifier ClipModeX="None" />
    <s:CursorModifier Name="CursorModifier" IsEnabled="{Binding ShowCursors, Mode=TwoWay}">
        <s:CursorModifier.LineOverlayStyle>
            <Style TargetType="Line">
                <Setter Property="Stroke" Value="LightGray" />
            </Style>
        </s:CursorModifier.LineOverlayStyle>
    </s:CursorModifier>
    <s:LegendModifier Margin="6"
                      GetLegendDataFor="AllSeries"
                      LegendPlacement="Inside"
                      Orientation="Horizontal"
                      ShowLegend="{Binding ShowLegend}"
                      ShowVisibilityCheckboxes="False" />
</s:ModifierGroup>

</s:SciChartSurface.ChartModifier>

When I attempt to change the background, I use the following:

<s:LegendModifier Margin="6"
GetLegendDataFor="AllSeries"
LegendPlacement="Inside"
Orientation="Horizontal"
    Background="{Binding BackgroundColor, Converter={StaticResource ColorToSolidColorBrushConverter}}"
ShowLegend="{Binding ShowLegend}"
ShowVisibilityCheckboxes="False" />

Which doesn’t work, though other color bindings in XAML work fine. If I change the color directly, say Background=”Red” or Background=”#FF0000″ It does not change either.

  • You must to post comments
Best Answer
0
0

Ok, so from your code sample, you’ve set LegendModifier.Background = … not SciChartLegend.Background = ….

If you want to style the SciChartLegend that the LegendModifier creates automatically, please try one of the following techniques:

Technique #1: Specify the LegendModifier.LegendTemplate

See SciChartLegend API Overview, Advanced Topics

<s:LegendModifier x:Name="legendModifier" ShowLegend="True" Orientation="Horizontal" Margin="10" >
    <s:LegendModifier.LegendTemplate>
        <ControlTemplate>
            <!-- Change the AutoGenerated SciChartLegend -->
            <s:SciChartLegend ItemTemplate="{Binding LegendItemTemplate}"
                LegendData="{Binding LegendData}"
                Orientation="{Binding Orientation}"
                ScrollViewer.HorizontalScrollBarVisibility="{Binding Path=(ScrollViewer.HorizontalScrollBarVisibility)}"
                ScrollViewer.VerticalScrollBarVisibility="{Binding Path=(ScrollViewer.VerticalScrollBarVisibility)}"
                ShowSeriesMarkers="{Binding ShowSeriesMarkers}"
                ShowVisibilityCheckboxes="{Binding ShowVisibilityCheckboxes}" />
        </ControlTemplate>
    </s:LegendModifier.LegendTemplate>
</s:LegendModifier>

Technique #2: Specify an unnamed style for TargetType SciChartLegend

<!-- Declare this in your UserControl.Resources -->
<Style TargetType="SciChartLegend">
    <Setter Property="Background" Value="Green"/>
</Style>

Best regards,
Andrew

  • You must to post comments
0
0

Hi Alex,

Thank you for your question! How are you changing the background color, do you have a code sample? What version of SciChart are you using? Finally, do you have a theme set or custom template or style?

I ask this because if I directly change the SciChartLegend.Background property in snoop, then the legend updates and shows the background color I chose.

Please update your question with a code sample + then comment here to let me know.

Best regards,
Andrew

Images
  • Alex Helms
    Original post updated. Thanks!
  • You must to post comments
0
0

I opted for using the style, works great. Makes sense in retrospect, thanks!

  • Andrew
    No probs! Some of the properties of LegendModifier are bound to the SciChartLegend it creates (like Margin, HorizontalAlignment etc...) but not Background.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.