Back to Devexpress

Axis2D.StripItemTemplate Property

wpf-devexpress-dot-xpf-dot-charts-dot-axis2d-e64c42b9.md

latest9.9 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public DataTemplate StripItemTemplate { get; set; }
vb
Public Property StripItemTemplate As DataTemplate

Property Value

TypeDescription
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.

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.

xaml
<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>
csharp
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"}
            };
        }
    }
}
vb
Imports DevExpress.Xpf.Charts
Imports System
Imports System.Collections.ObjectModel
Imports System.Windows.Media

Namespace ChartApp
    Public Partial Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub
    End Class
    Public Class MainWindowViewModel
        Private _Data As System.Collections.ObjectModel.ObservableCollection(Of ChartApp.DataPoint), _Strips As System.Collections.ObjectModel.ObservableCollection(Of ChartApp.StripData)

        Public Property Data As ObservableCollection(Of DataPoint)
            Get
                Return _Data
            End Get
            Private Set(ByVal value As ObservableCollection(Of DataPoint))
                _Data = value
            End Set
        End Property

        Public Property Strips As ObservableCollection(Of StripData)
            Get
                Return _Strips
            End Get
            Private Set(ByVal value As ObservableCollection(Of StripData))
                _Strips = value
            End Set
        End Property
        Public Sub New()
            Data = DataPoint.GetDataPoints()
            Strips = StripData.GetStripsData()
        End Sub
    End Class
    Public Class DataPoint
        Public Property Argument As Date
        Public Property Value As Double
        Public Shared Function GetDataPoints() As ObservableCollection(Of DataPoint)
            Return New ObservableCollection(Of DataPoint) From {
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 01),
                    .Value = 9.289R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 02),
                    .Value = 2.2727R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 03),
                    .Value = 3.7257R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 04),
                    .Value = 4.1825R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 05),
                    .Value = 2.1172R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 06),
                    .Value = 5.289R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 07),
                    .Value = 3.74R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 08),
                    .Value = 3.7257R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 09),
                    .Value = 4.1825R
                },
                New DataPoint With {
                    .Argument = New DateTime(2022, 01, 10),
                    .Value = 10.12R
                }
            }
        End Function
    End Class
    Public Class StripData
        Public Property Value1 As Double
        Public Property Value2 As Double
        Public Property Title As String

        Public Shared Function GetStripsData() As ObservableCollection(Of StripData)
            Return New ObservableCollection(Of StripData) From {
                New StripData With {
                    .Value1 = 3,
                    .Value2 = 5,
                    .Title = "Strip #1"
                },
                New StripData With {
                    .Value1 = 6,
                    .Value2 = 7,
                    .Title = "Strip #2"
                }
            }
        End Function
    End Class
End Namespace

See Also

Axis2D Class

Axis2D Members

DevExpress.Xpf.Charts Namespace