VIBlend
Home Products Downloads Purchase Support Forum About Blog

Scheduler Resources Binding

by viblend 24. July 2011 15:57

In this blog post, we will show you how to bind resources collection to the VIBlend Scheduler control.

1. To bind the Scheduler to Resources collection, you need to set its ResourcesSource property to point to the collection.

C#

List<Room> rentalUnits = new List<Room>();
string[] names = new string[] { "All Rooms", "1 bedroom condo #1", "1 bedroom condo #2", "2 bedroom condo #1", "2 bedroom condo #2", "2 bedroom condo #3", "3 bedroom condo #1", "3 bedroom Villa #1", "3 bedroom Villa #2", "4 bedroom Villa #1" };

for (int i = 0; i < names.Length; i++)
{
       Room room = new Room() { Name = names[i] };
       rentalUnits.Add(room);
}

this.Scheduler.ResourcesSource = rentalUnits;


VB .NET

Dim rentalUnits As List(Of Room) = New List(Of Room)()
Dim names() As String = { "All Rooms", "1 bedroom condo #1", "1 bedroom condo #2", "2 bedroom condo #1", "2 bedroom condo #2", "2 bedroom condo #3", "3 bedroom condo #1", "3 bedroom Villa #1", "3 bedroom Villa #2", "4 bedroom Villa #1" }

For i As Integer = 0 To names.Length - 1
       Dim room As New Room() With {.Name = names(i)}
       rentalUnits.Add(room)
Next i
Me.Scheduler.ResourcesSource = rentalUnits


2. The following example code represents the Room object that we used as Resource.

C#

public class Room
{
    public Room()
    {
    }
    
    public string Name
    {
        get;
        set;
    }
}

VB .NET

Public Class Room
    Public Sub New()
    End Sub

    Private privateName As String
    Public Property Name() As String
        Get
            Return privateName
        End Get
        Set(ByVal value As String)
            privateName = value
        End Set
    End Property
End Class

3. If you want to make some additional modifications to the resource before it appear in the Scheduler, you can subscribe to the ResourceCreated event.

C#

this.Scheduler.ResourceCreated += new EventHandler<ResourceEventArgs>(Scheduler_ResourceCreated);

VB .NET

AddHandler Scheduler.ResourceCreated, AddressOf Scheduler_ResourceCreated

4. In the event handler, you can customize the Resource's appearance by setting its Style or DataTemplate properties. The Style property allows you to change the resource's Background, Border and BorderThickness. Setting the DataTemplate property will change the entire look of the Resource.

C# 

  Color[] resourceColors = new Color[] { Color.FromArgb(255, 199, 203, 209), Color.FromArgb(255, 165, 191, 225), Color.FromArgb(255, 177, 205, 164), Color.FromArgb(255, 219, 172, 188),
            Color.FromArgb(255, 191, 175, 225), Color.FromArgb(255, 207, 193, 165), Color.FromArgb(255, 172, 188, 219), Color.FromArgb(255, 168, 197, 212), Color.FromArgb(255, 221, 172, 172),
        Color.FromArgb(255, 255, 230, 159)};
        int resourceIndex;

        void Scheduler_ResourceCreated(object sender, ResourceEventArgs e)
        {
            if (resourceIndex >= resourceColors.Length)
            {
                resourceIndex = 0;
            }

            // Set resource's style.
            StylePart style = new StylePart() { Background = new SolidColorBrush(resourceColors[resourceIndex]), BorderBrush = new SolidColorBrush(resourceColors[resourceIndex]), BorderThickness = new Thickness(1) };
            e.Resource.Style = style;
            resourceIndex++;
        }

VB .NET

  Private resourceColors() As Color = { Color.FromArgb(255, 199, 203, 209), Color.FromArgb(255, 165, 191, 225), Color.FromArgb(255, 177, 205, 164), Color.FromArgb(255, 219, 172, 188), Color.FromArgb(255, 191, 175, 225), Color.FromArgb(255, 207, 193, 165), Color.FromArgb(255, 172, 188, 219), Color.FromArgb(255, 168, 197, 212), Color.FromArgb(255, 221, 172, 172), Color.FromArgb(255, 255, 230, 159)}
        Private resourceIndex As Integer

        Private Sub Scheduler_ResourceCreated(ByVal sender As Object, ByVal e As ResourceEventArgs)
            If resourceIndex >= resourceColors.Length Then
                resourceIndex = 0
            End If

            ' Set resource's style.
            Dim style As New StylePart() With {.Background = New SolidColorBrush(resourceColors(resourceIndex)), .BorderBrush = New SolidColorBrush(resourceColors(resourceIndex)), .BorderThickness = New Thickness(1)}
            e.Resource.Style = style
            resourceIndex += 1
        End Sub



Download: SchedulerResources.zip

If you have any questions, please contact us at support@viblend.com

Tags:

Comments are closed

About the author

Some text that describes me

Tag cloud

Recent comments

Comment RSS
Copyright © 2011 VIBlend  
ALL RIGHTS RESERVED  
 
Terms of Use | Privacy Policy
WinForms Controls Purchase Online About Us
       
DataGrid Navigation Pane Technical Support Blog
ScrollBar TreeView
ListBox ProgressBar Downloads Register
ComboBox Buttons
TabControl Editors Documentation Client Login

VIBlend Blog is powered by BlogEngine.NET