Skip to main content

SchedulerViewBase.TimeRegionContentTemplateSelector Property

Specifies the object that chooses a time region template based on custom logic. This is a dependency property.

Namespace: DevExpress.Xpf.Scheduling

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

NuGet Package: DevExpress.Wpf.Scheduling

Declaration

public DataTemplateSelector TimeRegionContentTemplateSelector { get; set; }

Property Value

Type Description
DataTemplateSelector

A System.Windows.Controls.DataTemplateSelector descendant that chooses a template based on custom logic.

Remarks

A template that defines the presentation of time regions is specified by the TimeRegionContentTemplate property.

The example below illustrates how to apply different templates based on the time region’s Start property value:

     <dx:ThemedWindow.Resources>
        <DataTemplate  x:Key="timeRegionTextContentTemplate">
            <TextBlock Text="Break" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </DataTemplate>
        <DataTemplate  x:Key="timeRegionImageContentTemplate">
            <Image MaxHeight="28"
            Source="{dx:SvgImageSource Uri='pack://application:,,,/DevExpress.Images.v21.2;component/SvgImages/Icon Builder/Travel_Restaurant.svg'}" />
        </DataTemplate>
        <local:TimeRegionTemplateSelector x:Key="timeRegionTemplateSelector"
                                          TimeRegionTextContentTemplate="{StaticResource timeRegionTextContentTemplate}"
                                          TimeRegionImageContentTemplate="{StaticResource timeRegionImageContentTemplate}"/>
    </dx:ThemedWindow.Resources>
    ...
    <dxsch:SchedulerControl>
        <dxsch:SchedulerControl.TimeRegionItems>
            <dxsch:TimeRegionItem Start="{x:Static sys:DateTime.Today}" End="{x:Static sys:DateTime.Now}"
                                  BrushName="{x:Static dxsch:DefaultBrushNames.TimeRegion1Hatch}"
                                  />
        </dxsch:SchedulerControl.TimeRegionItems>
        <dxsch:DayView TimeRegionContentTemplateSelector="{StaticResource timeRegionTemplateSelector}" />
    </dxsch:SchedulerControl>
public class TimeRegionTemplateSelector : DataTemplateSelector {
    public DataTemplate TimeRegionTextContentTemplate { get; set; }
    public DataTemplate TimeRegionImageContentTemplate { get; set; }

    public override DataTemplate SelectTemplate(object item, DependencyObject container) {
        TimeRegionViewModel timeRegion = item as TimeRegionViewModel;
        if (timeRegion != null)
            return (timeRegion.TimeRegion.Start.Hour > 18) ? TimeRegionImageContentTemplate : TimeRegionTextContentTemplate;
        return base.SelectTemplate(item, container);
    }
}
See Also