Skip to main content

Axis2D.StripItemTemplate Property

Gets or sets the DataTemplate that specifies how to convert a model object to a strip.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v24.1.dll

NuGet Package: DevExpress.Wpf.Charts

Declaration

public DataTemplate StripItemTemplate { get; set; }

Property Value

Type Description
DataTemplate

A DataTemplate that specifies a generated strip’s parameters. The default is null (Nothing in Visual Basic).

Example

This example shows how to create horizontal strips for the y-axis based on a View Model’s collection of objects.

Strips are generated for the y-axis

To generate custom strips from a ViewModel, bind an axis’s StripItemsSource to a collection of objects that contain strip settings. Then, use the Axis2D.StripItemTemplate or Axis2D.StripItemTemplateSelector property to specify how to display the generated strips.

<Window xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"  
        x:Class="ChartApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ChartApp"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.DataContext>
        <local:MainWindowViewModel/>
    </Window.DataContext>
    <Grid>
        <dxc:ChartControl DataSource="{Binding Data}">
            <dxc:XYDiagram2D x:Name="diagram">
                <dxc:BarSideBySideSeries2D DisplayName="Annual Statistics" 
                                           ArgumentDataMember="Argument" 
                                           ValueDataMember="Value" />
                <dxc:XYDiagram2D.AxisY>
                    <dxc:AxisY2D StripItemsSource="{Binding Strips}" 
                                 LabelVisibilityMode="AutoGeneratedAndCustom" 
                                 Interlaced="False">
                        <dxc:AxisY2D.StripItemTemplate>
                            <DataTemplate>
                                <dxc:Strip MinLimit="{Binding Value1}" 
                                           MaxLimit="{Binding Value2}" 
                                           AxisLabelText="{Binding Title}"/>
                            </DataTemplate>
                        </dxc:AxisY2D.StripItemTemplate>
                        <dxc:AxisY2D.NumericScaleOptions>
                            <dxc:ContinuousNumericScaleOptions GridSpacing="1" 
                                                               AutoGrid="False"/>
                        </dxc:AxisY2D.NumericScaleOptions>
                    </dxc:AxisY2D>
                </dxc:XYDiagram2D.AxisY>
            </dxc:XYDiagram2D>
        </dxc:ChartControl>
    </Grid>
</Window>
using DevExpress.Xpf.Charts;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Media;

namespace ChartApp {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
    }
    public class MainWindowViewModel {
        public ObservableCollection<DataPoint> Data { get; private set; }
        public ObservableCollection<StripData> Strips { get; private set; }
        public MainWindowViewModel() {
            this.Data = DataPoint.GetDataPoints();
            this.Strips = StripData.GetStripsData();
        }
    }
    public class DataPoint {
        public DateTime Argument { get; set; }
        public double Value { get; set; }
        public static ObservableCollection<DataPoint> GetDataPoints() {
            return new ObservableCollection<DataPoint> {
                new DataPoint { Argument = new DateTime(2022,01,01), Value = 9.289D},
                new DataPoint { Argument = new DateTime(2022,01,02), Value = 2.2727D},
                new DataPoint { Argument = new DateTime(2022,01,03), Value = 3.7257D},
                new DataPoint { Argument = new DateTime(2022,01,04), Value = 4.1825D},
                new DataPoint { Argument = new DateTime(2022,01,05), Value = 2.1172D},
                new DataPoint { Argument = new DateTime(2022,01,06), Value = 5.289D},
                new DataPoint { Argument = new DateTime(2022,01,07), Value = 3.74D},
                new DataPoint { Argument = new DateTime(2022,01,08), Value = 3.7257D},
                new DataPoint { Argument = new DateTime(2022,01,09), Value = 4.1825D},
                new DataPoint { Argument = new DateTime(2022,01,10), Value = 10.12D}
            };
        }
    }
    public class StripData {
        public double Value1 { get; set; }
        public double Value2 { get; set; }
        public string Title { get; set; }

        public static ObservableCollection<StripData> GetStripsData() {
            return new ObservableCollection<StripData> {
                new StripData {Value1 = 3, Value2 = 5, Title = "Strip #1"},
                new StripData {Value1 = 6, Value2 = 7, Title = "Strip #2"}
            };
        }
    }
}
See Also