views:

95

answers:

1

I believe I'm using Silverlight 3.0... I just downloaded it this week. Assuming the charting namespace references the System.Windows.Controls.DataVisualization assembly in the Silverlight Toolkit, please help me create the DataPointStyle using C#, as it's expressed in XAML below:

<charting:Chart
    Title="Simple Column Annotations - Bottom">
    <charting:ColumnSeries
        DependentValuePath="Value"
        IndependentValuePath="Key"
        ItemsSource="{Binding}">
        <!-- HERE IS WHAT I WANT TO CREATE IN C#: -->
        <charting:ColumnSeries.DataPointStyle>
            <Style TargetType="charting:ColumnDataPoint">
                <Setter Property="Background" Value="Yellow"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:ColumnDataPoint">
                            <Grid>
                                <Rectangle
                                    Fill="{TemplateBinding Background}"
                                    Stroke="Black"/>
                                <Grid
                                    Background="#aaffffff"
                                    Margin="0 -20 0 0"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Bottom">
                                    <TextBlock
                                        Text="{TemplateBinding FormattedDependentValue}"
                                        FontWeight="Bold"
                                        Margin="2"/>
                                </Grid>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </charting:ColumnSeries.DataPointStyle>
        <!-- END -->
    </charting:ColumnSeries>
</charting:Chart>

My goal is to build a library of easy-to-use templates that can be applied to series in a chart. Thanks!

+2  A: 

You can't define control templates in C# alone. I'm not sure why you would want to?

Just add the XAML for your set of control templates as resources in your library. Use the XamlReader to load these templates into objects which you can then expose publicly.

AnthonyWJones
Ah, I see - thanks. I'll put the XAML into a resource dictionary.
Jeff Meatball Yang