Search code examples
c#silverlightxamltelerik

how to set Lineseries point template in code behind


Basically i would like to apply this XAML code in the C# behind. Here is the XAML

        <telerik:LineSeries Stroke="Transparent">
            <telerik:LineSeries.PointTemplate>
                <DataTemplate>
                    <Ellipse Height="10" Width="10" Fill="DarkGreen" />
                </DataTemplate>
            </telerik:LineSeries.PointTemplate>
        </telerik:LineSeries>

This is what i have tried:

Ellipse e = new Ellipse();
LineSeries line = new LineSeries();
e.Height = 10; 
e.Width = 10; 
line.Stroke = new SolidColorBrush(Colors.Transparent);
line.PointTemplate = new DataTemplate(e);

But it doesn't work i get a "Value for DataTemplate.DataType must be of the type System.Type." error. Anybody know how to correctly translate the XAML above?


Solution

  • This is what I do, I create a Resource:

    <UserControl.Resources>
        <DataTemplate x:Key="PointTemplate">
            <Ellipse Width="5" Height="5" Fill="Coral"/>
        </DataTemplate>
    </UserControl.Resources>
    

    Then you would apply it by doing:

    line.PointTemplate = this.Resources["PointTemplate"] as DataTemplate;