This is a migrated thread and some comments may be shown as answers.

CustomGridLine ElementStyle in code behind

2 Answers 68 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Veteran
Iron
Michael asked on 30 Aug 2012, 08:08 AM
Hy Telerik,

is it possible to set the ElementStyle from an CustomGridLine with an new style in Code behind.

I wana do something like this in code behind:

<Style x:Key="CustomGridLineCursorX3" TargetType="Line">
    <Setter Property="StrokeDashArray" Value="1" />
</Style>
this.GridLineCursorX7test = new CustomGridLine()
 {
    Stroke = new SolidColorBrush(Colors.Blue),
    StrokeThickness = 2,
    ElementStyle = this.Resources["CustomGridLineCursorX3"] as Style
    XIntercept = 2500
};

I try it with that code:
DoubleCollection dc = new DoubleCollection();
dc.Add(1.2);
 
Style style2 = new Style(typeof(System.Windows.Shapes.Line));
style2.Setters.Add(new Setter(System.Windows.Shapes.Line.VisibilityProperty, System.Windows.Visibility.Collapsed));
style2.Setters.Add(new Setter(System.Windows.Shapes.Line.StrokeDashArrayProperty, dc));
             
 
this.GridLineCursorX7test = new CustomGridLine()
{
    Stroke = new SolidColorBrush(Colors.Blue),
    StrokeThickness = 2,
    ElementStyle = style2,
    XIntercept = 2500
};
xChartArea.Annotations.Add(this.GridLineCursorX7test);

I know that the style works, because of the "VisibilityProperty".
I can set the VisibilityProperty to Visible and the CustomGridLine is visible.
And i can set it to Collapsed and the CustomGridLine is hidden.

Can you help me please!

2 Answers, 1 is accepted

Sort by
0
Accepted
Evgenia
Telerik team
answered on 03 Sep 2012, 02:33 PM
Hello Michael,

 Unfortunately this is easily reproducible bug of the Framework (as stated here) and you can use the approach suggested in this blogpost to work-around it.

All the best,
Evgenia
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Michael
Top achievements
Rank 1
Veteran
Iron
answered on 04 Sep 2012, 06:11 AM
Hy Evgenia,
thx for the reply. That helps me!
cheers mike
Tags
Chart
Asked by
Michael
Top achievements
Rank 1
Veteran
Iron
Answers by
Evgenia
Telerik team
Michael
Top achievements
Rank 1
Veteran
Iron
Share this question
or