Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9045947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:29:51+00:00 2026-06-16T11:29:51+00:00

I am drawing simple line charts using the WPF toolkit. My goal is to

  • 0

I am drawing simple line charts using the WPF toolkit. My goal is to set the line color of my series via Data Binding. This succeeds only partially. The question is: why?

Setup

Namespaces:

xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="WpfApplication3.MainWindow"
xmlns:media="clr-namespace:System.Windows.Media;assembly=PresentationCore"

Chart:

<chartingToolkit:Chart x:Name="chart">
    <chartingToolkit:LineSeries x:Name="seriesEntries" IndependentValueBinding="{Binding Key}" DependentValueBinding="{Binding Value}" DataPointStyle="{StaticResource CommonLineSeriesDataPoint}">
        <chartingToolkit:LineSeries.Tag>
            <media:Brush>Green</media:Brush>
        </chartingToolkit:LineSeries.Tag>
    </chartingToolkit:LineSeries>
</chartingToolkit:Chart>

Ignore the Tag for now, it will be relevant later.

Notice the chart has a custom data point style, CommonLineSeriesDataPoint:

<Style x:Key="CommonLineSeriesDataPoint" TargetType="chartingToolkit:LineDataPoint">
    <Setter Property="Background">
        <Setter.Value>
            <media:Brush>Red</media:Brush>
        </Setter.Value>
    </Setter>
</Style>
<Style TargetType="chartingToolkit:LineSeries">
    <Setter Property="DataPointStyle" Value="{StaticResource CommonLineSeriesDataPoint}" />
</Style>

As expected, this colors my line series red:

Red line series

Breaking Change

Now I want to data bind my data point background. I make only one change. Instead of specifying the background brush directly, I bind it to the Tag property of my LineSeries, which is also a brush (see previous LineSeries declaration, it’s a green one).

<Style x:Key="CommonLineSeriesDataPoint" TargetType="chartingToolkit:LineDataPoint">
    <Setter Property="Background">
        <Setter.Value>
            <Binding Path="Tag" RelativeSource="{RelativeSource AncestorType={x:Type chartingToolkit:LineSeries}}" />
        </Setter.Value>
    </Setter>
</Style>
<Style TargetType="chartingToolkit:LineSeries">
    <Setter Property="DataPointStyle" Value="{StaticResource CommonLineSeriesDataPoint}" />
</Style>

The result is this:

enter image description here

So the dots are green. But the line is gone.

My expectation is to see a green line as well! Where is it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:29:52+00:00Added an answer on June 16, 2026 at 11:29 am

    I found a solution after digging in the WPF Toolkit Sources.

    Turns out the Stroke property of the series’ Polyline is bound to a Background property via TemplateBinding. I suspect this doesn’t go well with my try binding the Background property itself.

    This answer on SO suggests that TemplateBinding is evaluated at compile time. So let’s get rid of the TemplateBinding and bind the Stroke property directly to the Tag of my LineSeries (remember: the Tag contains the green brush).

    From the WPF Toolkit Source \Source\DataVisualization\Themes\generic.xaml I copied part of the style definition for the LineSeries and added it to my ResourceDictionary:

    <Style x:Key="CommonLineSeries" TargetType="chartingToolkit:LineSeries" BasedOn="{StaticResource {x:Type chartingToolkit:LineSeries}}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="chartingToolkit:LineSeries">
                    <Canvas x:Name="PlotArea">
                        <Polyline Points="{TemplateBinding Points}" Stroke="{Binding Tag, RelativeSource={RelativeSource AncestorType={x:Type chartingToolkit:LineSeries}}}" Style="{TemplateBinding PolylineStyle}"/>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    (If interested you can search for <!-- charting:LineSeries --> in generic.xaml to find the source I copied from.)

    The only thing I modified is the binding of Stroke. Here I use the same binding I used for my data points.

    Last thing to do: tell the LineSeries to use this style:

    <chartingToolkit:LineSeries x:Name="seriesEntries" IndependentValueBinding="{Binding Key}" DependentValueBinding="{Binding Value}" DataPointStyle="{StaticResource CommonLineSeriesDataPoint}" Style="{StaticResource CommonLineSeries}">
    

    And lo and behold, it works. The line is back and it’s green:

    Diagram - Line Color Fixed

    (If you look closely you see that the legend entry for the series still has the wrong color. But I assume the solution will be quite similar to the above.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm drawing simple text in HTML5 canvas using this: context.fillStyle = #FF0000 context.font =
I need to create a simple drawing app. This app consists of a line
I'm working on a simple drawing application. My line is constructed using polygons and
Here is a simple drawing - (void)drawRect:(CGRect)rect { //vertical line with 1 px stroking
I am having trouble drawing a line within a group box in a simple
I'm making a simple drawing app on Android. I'm using the FingerPaint.java provided with
I have to create a simple 2D animation without using various primitives for drawing
Just drawing a simple text line. With TLF text it looks pixelated and with
I am trying to make a simple line drawing program in java, I am
I am trying to add a simple line graph in excel automatically by using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.