Overriding DataPointStyle in a WPF Toolkit Chart

久未见 提交于 2019-12-05 14:06:00

Until someone suggests a better method, I've manually set the colors. I guess I won't be using the automatic palette for now.

<Style
    x:Key="SimpleDataPointStyle"
    BasedOn="{StaticResource {x:Type charting:LineDataPoint}}"
    TargetType="{x:Type charting:LineDataPoint}">
    <Setter Property="Width" Value="20" />
    <Setter Property="Height" Value="20" />
</Style>

...

<chart:LineSeries ... >
    <chart:DataPointSeries.DataPointStyle>
        <Style
            BasedOn="{StaticResource SimpleDataPointStyle}"
            TargetType="{x:Type charting:LineDataPoint}">
            <Setter Property="Background" Value="Green" />
        </Style>
    </chart:DataPointSeries.DataPointStyle>
</chart:LineSeries>
<chart:LineSeries ... >
    <chart:DataPointSeries.DataPointStyle>
        <Style
            BasedOn="{StaticResource SimpleDataPointStyle}"
            TargetType="{x:Type charting:LineDataPoint}">
            <Setter Property="Background" Value="Red" />
        </Style>
    </chart:DataPointSeries.DataPointStyle>
</chart:LineSeries>
tdc

For those interested this can also be done in the code behind that adds a new LineSeries as follows:

ResourceDictionary rd = MyChart.Palette[MyChart.Series.Count % MyChart.Palette.Count];
Style style = new Style(typeof(LineDataPoint), rd["DataPointStyle"] as Style);
style.Setters.Add(new Setter(OpacityProperty, 0.0));

LineSeries ls = new LineSeries()
{
    DataPointStyle = style
};
MyChart.Series.Add(ls);
Paul Haley

I have just posted a solution to this here.

instead of <Setter Property="Background" Value="Green" /> just bind the value to color as a property of the model. So <Setter Property="Background" Value="{Binding Path=Color}" />

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!