Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3590
How to link the series title color in the legend to the series brush color?
posted

I have created a custom data template for the LegendItemTemplate for my series and I have a legend style specified for the legend itself but I am not sure how to make the Series.Title in the data template use the Series.ActualBrush as its color. Here is my data template. All I did was remove the ItemDataBadgeTemplate.

 

<DataTemplate x:Key="LegendItemTemplate">
            <StackPanel Orientation="Horizontal" Margin="1" Visibility="{Binding Series.Visibility}">
                <ContentPresenter Content="{Binding Series.Title, TargetNullValue=Series Title}" />
            </StackPanel>
</DataTemplate>

 

If I add the binding to the legend style I don't have access to the Series object...it uses the control's datacontext which is my custom viewmodel.


Legend style:

<Style x:Key="LegendStyle" TargetType="ig:Legend">
   <Setter Property="Opacity" Value="1" />
   <Setter Property="Background" Value="Transparent" />
   <Setter Property="Margin" Value="0" />
   <Setter Property="BorderThickness" Value="0" />
   <Setter Property="Foreground" Value="{Binding Series.ActualBrush}" />
</Style>

XamDock XAML:

<ig:XamDock x:Name="XamDataChartContainer" Margin="0" Grid.Row="0">
    <ig:XamDock.Height>
        <MultiBinding Converter="{StaticResource WaveCollectionToHeightConverter}">
            <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=UserControl}" Path="DataContext.SelectedWaveForms" />
            <Binding ElementName="WaveFormCtrl" Path="Height" />
        </MultiBinding>
    </ig:XamDock.Height>
    <ig:XamDataChart 
        x:Name="xmDataChart"
        Margin="0" 
        CrosshairVisibility="Collapsed"
        VerticalZoomable="False"
        VerticalZoombarVisibility="Collapsed"
        HorizontalZoomable="False"
        HorizontalZoombarVisibility="Collapsed"
        Visibility="{Binding Selected,Converter={StaticResource BooleanToVisibilityConverter}}"
        Background="Black" 
        PlotAreaBorderBrush="Black" 
        PlotAreaBackground="Black"
        Legend="{Binding ElementName=xmLegendOTC}" >
        <ig:XamDataChart.Axes>
            <ig:CategoryXAxis x:Name="xmXAxis" ItemsSource="{Binding WaveData}" Label="{}{TimeStamp}" Stroke="Transparent" MajorStroke="Transparent">
                <ig:CategoryXAxis.LabelSettings>
                    <ig:AxisLabelSettings Location="InsideBottom" Visibility="Collapsed" />
                </ig:CategoryXAxis.LabelSettings>
            </ig:CategoryXAxis>
            <ig:NumericYAxis x:Name="xmYAxis" MajorStroke="Transparent" MinorStroke="Transparent">
                <ig:NumericYAxis.LabelSettings>
                    <ig:AxisLabelSettings Location="InsideLeft" Visibility="Collapsed" />
                </ig:NumericYAxis.LabelSettings>
            </ig:NumericYAxis>
        </ig:XamDataChart.Axes>
        <ig:XamDataChart.Series>
            <ig:LineSeries
                LegendItemTemplate="{StaticResource LegendItemTemplate}"
                Thickness="2" 
                ItemsSource="{Binding WaveData}" 
                Brush="Green" 
                MarkerType="None"
                UnknownValuePlotting="DontPlot" 
                ValueMemberPath="Value" 
                XAxis="{Binding ElementName=xmXAxis}" 
                YAxis="{Binding ElementName=xmYAxis}" 
                Title="{Binding WaveChannelName}" />
        </ig:XamDataChart.Series>
    </ig:XamDataChart>
    <ig:Legend x:Name="xmLegendOTC"
        ig:XamDock.Edge="InsideTop"
        ig:XamDock.HorizontalDockAlignment="Left"
        ig:XamDock.VerticalDockAlignment="Top"
        Style="{StaticResource LegendStyle}">
    </ig:Legend>
    <StackPanel Orientation="Vertical" 
        ig:XamDock.Edge="InsideRight"
        ig:XamDock.VerticalDockAlignment="Top"
        Margin="0,0,0,0" >
        <TextBlock x:Name="Offset" Text="{Binding Offset, StringFormat=Offset: {0}}" 
Visibility="Visible" Margin="0,0,0,0" />
<TextBlock x:Name="LastDisplayed" 
Text="{Binding LastDisplayedTimeStamp, StringFormat=LastDisplayedTimestamp: {0:hh:mm:ss:fff}}" 
Visibility="Visible" HorizontalAlignment="Left" Margin="0,0,0,0"/>
<TextBlock x:Name="BufferSize" Text="{Binding BufferSize, StringFormat=BufferSize: {0}}" 
Visibility="Visible" Margin="0,0,0,0" />
<TextBlock x:Name="CurrentDrawPosition" 
Text="{Binding CurrentPosition, StringFormat=CurrentDrawPosition: {0}}" 
Visibility="Visible" Margin="0,0,0,0" />
<TextBlock x:Name="LastBufferTime"
  Text="{Binding DebugLastTimeStamp, StringFormat=LastBufferTime: {0:hh:mm:ss:fff}}" 
  Visibility="Visible" Margin="0,0,0,0" />
     </StackPanel>
</ig:XamDock>