New to Telerik UI for WPF? Download free 30-day trial

Styling the GridLine

The axis grid lines are part of the chart axis and are represented by the Line control. To create a style for them in Expression Blend use a dummy control and after modifying it, set it to the AxisStyles complex property of the Axis.

Open your RadChart project in Expression Blend. To add the dummy Line control you have to go to the XAML view. To do that select View -> Active Document View -> XAML View from the menu. Declare a Line control in your XAML.

<Grid x:Name="LayoutRoot" 
    <Line /> 

To go back to the design view select View -> Active Document View -> Design View from the menu. In the 'Objects and Timeline' pane select the newly created Line control. And select Object -> Edit Style -> Create Empty from the menu*. *You will be prompted for the name of the style and where to be placed within your application.

If you choose to define the style in Application, it would be available for the entire application. This allows you to define a style only once and then reuse it where needed.

After clicking the OK button, a style with target type Line will be created and the properties for this type will be loaded in the 'Properties' pane. Modify them until you get the desired appearance.

After finishing with the changes, it is time to set the style. It can be set only through the procedural code, which means that you have to go to the Visual Studio and modify the code-behind file of your UserControl.

this.radChart.DefaultView.ChartArea.AxisX.AxisStyles.GridLineStyle = this.Resources["GridLineStyle"] as Style; 
this.radChart.DefaultView.ChartArea.AxisY.AxisStyles.GridLineStyle = this.Resources["GridLineStyle"] as Style; 
Me.radChart.DefaultView.ChartArea.AxisX.AxisStyles.GridLineStyle = TryCast(Me.Resources("GridLineStyle"), Style) 
Me.radChart.DefaultView.ChartArea.AxisY.AxisStyles.GridLineStyle = TryCast(Me.Resources("GridLineStyle"), Style) 

To show the grid lines for a particular axis you have to set its MajorGridLinesVisibility property to Visible. Read more about grid lines here.

Here is a snapshot of the sample result.

WPF RadChart

Here is the final XAML for the Style:

<Style x:Key="GridLineStyle" TargetType="Line"> 
    <Setter Property="Stroke" Value="Orange" /> 
    <Setter Property="StrokeThickness" Value="5" /> 

See Also

In this article