Back to Devexpress

DayViewBase.TimeRulersSource Property

wpf-devexpress-dot-xpf-dot-scheduling-dot-dayviewbase.md

latest8.7 KB
Original Source

DayViewBase.TimeRulersSource Property

Gets or sets the source from which time rulers are generated. This is a dependency property.

Namespace : DevExpress.Xpf.Scheduling

Assembly : DevExpress.Xpf.Scheduling.v25.2.dll

NuGet Package : DevExpress.Wpf.Scheduling

Declaration

csharp
public IEnumerable TimeRulersSource { get; set; }
vb
Public Property TimeRulersSource As IEnumerable

Property Value

TypeDescription
IEnumerable

A collection that is used to generate time rulers.

|

Remarks

Your Model or ViewModel can define a collection of objects that contain time ruler settings. You can use the DayViewBase.TimeRulersSource property to bind a scheduler view to such a collection. The SchedulerControl applies these settings to a generic time ruler template. You can specify that template in the TimeRulerTemplate property.

Example

The following example demonstrates how to add multiple time rulers to the scheduler’s Day View using the MVVM architectural pattern.

Use the DayViewBase.TimeRulersSource property to bind the view to a collection of objects containing time ruler settings described in the ViewModel. The DayViewBase.TimeRulerTemplate property specifies a data template based on which time rulers are generated.

Create a custom style for the TimeRulerCellControl to specify format strings for displaying time in the time rulers’ time scale.

View Example

xaml
<dx:ThemedWindow x:Class="WpfSchedulerTimeRulers.MainWindow" mc:Ignorable="d" Title="Time Rulers" Height="500" Width="800" 
    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:WpfSchedulerTimeRulers"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:dxsch="http://schemas.devexpress.com/winfx/2008/xaml/scheduling"
    xmlns:dxschv="http://schemas.devexpress.com/winfx/2008/xaml/scheduling/visual"
    DataContext="{dxmvvm:ViewModelSource local:MainViewModel}">

    <dx:ThemedWindow.Resources>
        <DataTemplate x:Key="TimeRulerGeneratorTemplate">
            <ContentControl>
                <dxsch:TimeRuler Caption="{Binding Caption}" ShowMinutes="{Binding ShowMinutes}" TimeZone="{Binding TimeZone}" AlwaysShowTimeDesignator="{Binding AlwaysShowTimeDesignator}"/>
            </ContentControl>
        </DataTemplate>

        <Style TargetType="{x:Type dxschv:TimeRulerCellControl}">
            <Setter Property="HourStringFormat" Value="{}{0:HH}"/>
            <Setter Property="MinuteStringFormat" Value="{}{0:mm}"/>
        </Style>
    </dx:ThemedWindow.Resources>

    <Grid>
        <dxsch:SchedulerControl x:Name="scheduler">
            <dxsch:DayView x:Name="dayView" ShowWorkTimeOnly="True" TimeScale="00:30:00" TimeRulersSource="{Binding TimeRulers}" TimeRulerTemplate="{StaticResource TimeRulerGeneratorTemplate}"/>
        </dxsch:SchedulerControl>
    </Grid>
</dx:ThemedWindow>
vb
Imports System
Imports System.Collections.ObjectModel
Imports DevExpress.Mvvm.POCO

Namespace WpfSchedulerTimeRulers
    Public Class MainViewModel
        Private privateTimeRulers As ObservableCollection(Of TimeRulerViewModel)
        Public Overridable Property TimeRulers() As ObservableCollection(Of TimeRulerViewModel)
            Get
                Return privateTimeRulers
            End Get
            Protected Set(ByVal value As ObservableCollection(Of TimeRulerViewModel))
                privateTimeRulers = value
            End Set
        End Property

        Protected Sub New()
            CreateTimeRulers()
        End Sub

        Private Sub CreateTimeRulers()
            TimeRulers = New ObservableCollection(Of TimeRulerViewModel)()
            TimeRulers.Add(TimeRulerViewModel.Create("GMT", TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time")))
            TimeRulers.Add(TimeRulerViewModel.Create("Local", TimeZoneInfo.Local))
        End Sub
    End Class

    Public Class TimeRulerViewModel
        Public Shared Function Create() As TimeRulerViewModel
            Return ViewModelSource.Create(Function() New TimeRulerViewModel())
        End Function

        Public Shared Function Create(ByVal caption As String, ByVal timeZoneInfo As TimeZoneInfo) As TimeRulerViewModel
            Dim timeRuler As TimeRulerViewModel = TimeRulerViewModel.Create()
            timeRuler.Caption = caption
            timeRuler.TimeZone = timeZoneInfo
            timeRuler.AlwaysShowTimeDesignator = False
            timeRuler.ShowMinutes = False
            Return timeRuler
        End Function

        Protected Sub New()
        End Sub
        Public Overridable Property Caption() As String
        Public Overridable Property TimeZone() As TimeZoneInfo
        Public Overridable Property AlwaysShowTimeDesignator() As Boolean
        Public Overridable Property ShowMinutes() As Boolean
    End Class
End Namespace
csharp
using System;
using System.Collections.ObjectModel;
using DevExpress.Mvvm.POCO;

namespace WpfSchedulerTimeRulers
{
    public class MainViewModel
    {
        public virtual ObservableCollection<TimeRulerViewModel> TimeRulers { get; protected set; }

        protected MainViewModel()
        {
            CreateTimeRulers();
        }

        private void CreateTimeRulers()
        {
            TimeRulers = new ObservableCollection<TimeRulerViewModel>();
            TimeRulers.Add(TimeRulerViewModel.Create("GMT", TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time")));
            TimeRulers.Add(TimeRulerViewModel.Create("Local", TimeZoneInfo.Local));
        }
    }

    public class TimeRulerViewModel
    {
        public static TimeRulerViewModel Create()
        {
            return ViewModelSource.Create(() => new TimeRulerViewModel());
        }

        public static TimeRulerViewModel Create(string caption, TimeZoneInfo timeZoneInfo)
        {
            TimeRulerViewModel timeRuler = TimeRulerViewModel.Create();
            timeRuler.Caption = caption;
            timeRuler.TimeZone = timeZoneInfo;
            timeRuler.AlwaysShowTimeDesignator = false;
            timeRuler.ShowMinutes = false;
            return timeRuler;
        }

        protected TimeRulerViewModel() { }
        public virtual string Caption { get; set; }
        public virtual TimeZoneInfo TimeZone { get; set; }
        public virtual bool AlwaysShowTimeDesignator { get; set; }
        public virtual bool ShowMinutes { get; set; }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the TimeRulersSource property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-scheduler-generate-time-rulers-from-view-model-collection/CS/WpfSchedulerTimeRulers/MainWindow.xaml#L28

xml
<dxsch:SchedulerControl x:Name="scheduler">
    <dxsch:DayView x:Name="dayView" ShowWorkTimeOnly="True" TimeScale="00:30:00" TimeRulersSource="{Binding TimeRulers}" TimeRulerTemplate="{StaticResource TimeRulerGeneratorTemplate}"/>
</dxsch:SchedulerControl>

See Also

DayViewBase Class

DayViewBase Members

DevExpress.Xpf.Scheduling Namespace