开发者

Changing the data point appearance of a series

I am new to Silverlight and the Silverlight.Controls.Toolkit having only been exposed to either for a couple of weeks (I also have no WPF experience).

I am trying to adapt the toolkit's charting to allow the style of the data points on certain types of series to be changed by the user when viewing the chart.

For example, a line series which is showing data points currently always show the points as circles. I want the user to be able to select a shape to be used to draw the data points.

The only way I have achieved this so far is be defining styles in a resource dictionary:

<Style x:Key="SquareDataPointStyle" TargetType="charting:LineDataPoint">
        <Setter Property="Background" Value="Black" />
        <Setter Property="BorderBrush" Value="Gray"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Width" Value="8" />
        <Setter Property="Height" Value="8" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="charting:LineDataPoint">
                    <Grid x:N开发者_开发百科ame="Root" Opacity="1">
                        <VisualStateManager.VisualStateGroups>
                            ...
                        </VisualStateManager.VisualStateGroups>
                        <ToolTipService.ToolTip>
                            <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                        </ToolTipService.ToolTip>
                        <Rectangle Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" />
                        <Rectangle x:Name="SelectionHighlight" Opacity="0" Fill="Red" />
                        <Rectangle x:Name="MouseOverHighlight" Opacity="0" Fill="White" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

..and then setting the data point style programmatically, using the predefined style's key:

series.DataPointStyle = (Style)Application.Current.Resources["SquareDataPointStyle"];            

This doesn't seem like a good way to go about it as the style definition is lengthy for each DataPoint Style and I only want to vary what shape is being drawn - not the background/tooltip etc.

What would be the cleanest/most 'correct' way to go about this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜