CustomGridLine ElementStyle in code behind

3 posts, 1 answers
  1. Michael
    Michael avatar
    35 posts
    Member since:
    Jan 2012

    Posted 30 Aug 2012 Link to this post

    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. Answer
    Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 03 Sep 2012 Link to this post

    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.

  3. DevCraft banner
  4. Michael
    Michael avatar
    35 posts
    Member since:
    Jan 2012

    Posted 04 Sep 2012 Link to this post

    Hy Evgenia,
    thx for the reply. That helps me!
    cheers mike
Back to Top