このトピックは、カスタム カレンダー クラスを作成して xamGantt と使用する方法を紹介します 。
このトピックを理解するためには、以下のトピックを理解しておく必要があります。
このトピックには次のセクションがあります。
xamGantt ListBackedProject とカスタム カレンダー クラスを使用できます。ListBackedProject
は指定された TaskItemsSource からタスク情報を取得するプロジェクトです。カスタム カレンダーを使用するためには、ListBackedProject
の CalendarItemsSource プロパティと CalendarId プロパティを設定します。
以下の表にカスタム カレンダーと使用する時の ListBackedProject の主要プロパティをまとめます。
CalendarPropertyMapping
の使用は、 ProjectCalendarPropertyMapping オブジェクトの設定で構成されます。ProjectCalendarPropertyMapping
は、CalendarItemsSource によって指定されるデータ ソース内の特定のフィールドに関する情報、および ProjectCalendar
オブジェクトのどのプロパティにフィールドがマップされるかの情報を含みます。
ProjectCalendar
オブジェクトのプロパティは、 CalendarProperty によって識別され、データ ソース内のフィールドは、 DataObjectProperty によって識別されます。
カスタム カレンダーの使用はプロジェクトの開始日によって影響されます。開始時間を設定しない場合には、デフォルト設定の今日の 8:00 AM が使用されます。たとえば、カスタム カレンダーを作成し、稼働時間が 8:00 AM よりも早く始まる、たとえば 7:00 AM に始まり、自動スケジュール タスクを使用する場合は、最初のタスクは 7:00 AM からではなく 8:00 AMから開始します。
このコード例はカスタム カレンダー クラスの 2 つのインスタンスを作成し、ListBackedProject の CalendarItemSource として設定します。CalendarId プロパティを設定することによって、2 番目のカレンダーは現在のプロジェクト カレンダーになります。
コード例には、使用中のカレンダーをどのように説明するかを示すためにタスクのコレクションが含まれます。
コード例を完了するには xamGantt プロジェクトが必要です。サンプルの xamGantt プロジェクトを作成するためには、 xamGantt をページに追加の指示に従ってください。
次にプロジェクトを若干変更する必要があります。以下のクラスがなければなりません。
CustomCalendar
.このクラスの完全なコードを確認するには、 カスタム カレンダーのコード例を参照してください。
CustomTask
このクラスの完全なコードを確認するには、 カスタム タスクのコード例を参照してください。
次にマークアップと ViewModel をこのトピックで示されるもので置き換える必要があります。
以下は完全なサンプル プロジェクトのプレビューです。月曜日、水曜日、金曜日の場合、稼働時間は 7:00 AM から 4:00 PM で、休憩時間は 11:00 AM から 12:00 AM です。火曜日と木曜日は、稼働時間は 9:00 AM から 6:00 AM で休憩時間は 1:00 PM から 2:00 PM までです。
XAML の場合:
<Grid>
<Grid.Resources>
<local:CustomCalendarViewModel x:Key="dc" />
</Grid.Resources>
<Grid.DataContext>
<Binding Source="{StaticResource dc}" />
</Grid.DataContext>
<ig:XamGantt x:Name="xamGantt">
<ig:XamGantt.Project>
<ig:ListBackedProject TaskItemsSource="{Binding Tasks}" CalendarItemsSource="{Binding Calendars}"
CalendarId="C2" Start="{Binding Today}">
<ig:ListBackedProject.TaskPropertyMappings>
<ig:ProjectTaskPropertyMapping TaskProperty="DataItemId" DataObjectProperty="DataItemId" />
<ig:ProjectTaskPropertyMapping TaskProperty="TaskName" DataObjectProperty="TaskName" />
<ig:ProjectTaskPropertyMapping TaskProperty="Start" DataObjectProperty="Start" />
<ig:ProjectTaskPropertyMapping TaskProperty="Duration" DataObjectProperty="Duration" />
<ig:ProjectTaskPropertyMapping TaskProperty="Tasks" DataObjectProperty="Tasks" />
<ig:ProjectTaskPropertyMapping TaskProperty="Predecessors" DataObjectProperty="Predecessors" />
<ig:ProjectTaskPropertyMapping TaskProperty="ConstraintDate" DataObjectProperty="ConstraintDate" />
<ig:ProjectTaskPropertyMapping TaskProperty="ConstraintType" DataObjectProperty="ConstraintType" />
<ig:ProjectTaskPropertyMapping TaskProperty="DurationFormat" DataObjectProperty="DurationFormat" />
</ig:ListBackedProject.TaskPropertyMappings>
<ig:ListBackedProject.CalendarPropertyMappings>
<ig:ProjectCalendarPropertyMapping CalendarProperty="UniqueId" DataObjectProperty="Id" />
<ig:ProjectCalendarPropertyMapping CalendarProperty="DaysOfWeek" DataObjectProperty="DaysOfWeek" />
<ig:ProjectCalendarPropertyMapping CalendarProperty="DisplayName" DataObjectProperty="DisplayName" />
</ig:ListBackedProject.CalendarPropertyMappings>
</ig:ListBackedProject>
</ig:XamGantt.Project>
</ig:XamGantt>
</Grid>
C# の場合:
public class CustomCalendarViewModel : INotifyPropertyChanged
{
private ObservableCollection<CustomCalendar> calendars;
private ObservableCollection<CustomTask> tasks;
public ObservableCollection<CustomCalendar> Calendars
{
get
{
if (calendars == null)
{
calendars = GenerateCustomCalendars();
}
return calendars;
}
set { calendars = value; }
}
public ObservableCollection<CustomTask> Tasks
{
get
{
if (tasks == null)
{
tasks = GenerateCustomTasks();
}
return tasks;
}
set { tasks = value; }
}
public DateTime Today
{
get { return DateTime.Today; }
}
private ObservableCollection<CustomTask> GenerateCustomTasks()
{
return new ObservableCollection<CustomTask>()
{
new CustomTask { DataItemId = "t1", TaskName = "Task 1", Duration = TimeSpan.FromHours(8), DurationFormat = "Days" },
new CustomTask { DataItemId = "t2", TaskName = "Task 2", Duration = TimeSpan.FromHours(24), Predecessors = "t1", DurationFormat = "ElapsedDays" },
new CustomTask { DataItemId = "t3", TaskName = "Task 3", Duration = TimeSpan.FromHours(8), Predecessors = "t2", DurationFormat = "Days" },
new CustomTask { DataItemId = "t4", TaskName = "Task 4", Duration = TimeSpan.FromHours(48), Predecessors = "t3", DurationFormat = "ElapsedDays" },
new CustomTask { DataItemId = "t5", TaskName = "Task 5", Duration = TimeSpan.FromDays(1), Predecessors = "t4", DurationFormat = "Days" },
new CustomTask { DataItemId = "t6", TaskName = "Task 6", Duration = TimeSpan.FromDays(1), Predecessors = "t5", DurationFormat = "ElapsedDays" },
new CustomTask { DataItemId = "t7", TaskName = "Task 7", Duration = TimeSpan.FromHours(8), Predecessors = "t6", DurationFormat = "Days" },
new CustomTask { DataItemId = "t8", TaskName = "Task 8", Duration = TimeSpan.FromHours(8), Predecessors = "t7", DurationFormat = "ElapsedDays" }
};
}
#region Private helper methods
private ObservableCollection<CustomCalendar> GenerateCustomCalendars()
{
return new ObservableCollection<CustomCalendar>()
{
new CustomCalendar
{
Id = "C1",
Name = "Calendar 1",
DaysOfWeek=@"
<ScheduleDaysOfWeek>
<Monday>
<ScheduleDayOfWeek>
<DaySettings>
<DaySettings IsWorkday=""false"" />
</DaySettings>
</ScheduleDayOfWeek>
</Monday>
<Saturday>
<ScheduleDayOfWeek>
<DaySettings>
<DaySettings IsWorkday=""true"">
<WorkingHours>
<WorkingHoursCollection>
<TimeRange Start=""PT8H"" End=""PT12H"" />
<TimeRange Start=""PT13H"" End=""PT17H"" />
</WorkingHoursCollection>
</WorkingHours>
</DaySettings>
</DaySettings>
</ScheduleDayOfWeek>
</Saturday>
</ScheduleDaysOfWeek>",
CustomDescription = "This custom calendar has a Monday as a nonworking day and Saturday as a working day"
},
new CustomCalendar
{
Id = "C2",
Name = "Calendar 2",
DaysOfWeek = @"
<ScheduleDaysOfWeek>
<Monday>
<ScheduleDayOfWeek>
<DaySettings>
<DaySettings IsWorkday=""true"">
<WorkingHours>
<WorkingHoursCollection>
<TimeRange Start=""PT7H"" End=""PT11H"" />
<TimeRange Start=""PT12H"" End=""PT16H"" />
</WorkingHoursCollection>
</WorkingHours>
</DaySettings>
</DaySettings>
</ScheduleDayOfWeek>
</Monday>
<Tuesday>
<ScheduleDayOfWeek>
<DaySettings>
<DaySettings IsWorkday=""true"">
<WorkingHours>
<WorkingHoursCollection>
<TimeRange Start=""PT9H"" End=""PT13H"" />
<TimeRange Start=""PT14H"" End=""PT18H"" />
</WorkingHoursCollection>
</WorkingHours>
</DaySettings>
</DaySettings>
</ScheduleDayOfWeek>
</Tuesday>
<Wednesday>
<ScheduleDayOfWeek>
<DaySettings>
<DaySettings IsWorkday=""true"">
<WorkingHours>
<WorkingHoursCollection>
<TimeRange Start=""PT7H"" End=""PT11H"" />
<TimeRange Start=""PT12H"" End=""PT16H"" />
</WorkingHoursCollection>
</WorkingHours>
</DaySettings>
</DaySettings>
</ScheduleDayOfWeek>
</Wednesday>
<Thursday>
<ScheduleDayOfWeek>
<DaySettings>
<DaySettings IsWorkday=""true"">
<WorkingHours>
<WorkingHoursCollection>
<TimeRange Start=""PT9H"" End=""PT13H"" />
<TimeRange Start=""PT14H"" End=""PT18H"" />
</WorkingHoursCollection>
</WorkingHours>
</DaySettings>
</DaySettings>
</ScheduleDayOfWeek>
</Thursday>
<Friday>
<ScheduleDayOfWeek>
<DaySettings>
<DaySettings IsWorkday=""true"">
<WorkingHours>
<WorkingHoursCollection>
<TimeRange Start=""PT7H"" End=""PT11H"" />
<TimeRange Start=""PT12H"" End=""PT16H"" />
</WorkingHoursCollection>
</WorkingHours>
</DaySettings>
</DaySettings>
</ScheduleDayOfWeek>
</Friday>
</ScheduleDaysOfWeek>",
CustomDescription = "This custom calendar sets the following working times: From 9:00to 13:00 and from 14:00 to 18:00"
}
};
}
#endregion // Private helper methods
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion // INotifyPropertyChanged
}
Visual Basic の場合:
Public Class CustomCalendarViewModel
Implements INotifyPropertyChanged
Private m_calendars As ObservableCollection(Of CustomCalendar)
Private m_tasks As ObservableCollection(Of CustomTask)
Public Property Calendars() As ObservableCollection(Of CustomCalendar)
Get
If m_calendars Is Nothing Then
m_calendars = GenerateCustomCalendars()
End If
Return m_calendars
End Get
Set
m_calendars = value
End Set
End Property
Public Property Tasks() As ObservableCollection(Of CustomTask)
Get
If m_tasks Is Nothing Then
m_tasks = GenerateCustomTasks()
End If
Return m_tasks
End Get
Set
m_tasks = value
End Set
End Property
Public ReadOnly Property Today() As DateTime
Get
Return DateTime.Today
End Get
End Property
Private Function GenerateCustomTasks() As ObservableCollection(Of CustomTask)
Return New ObservableCollection(Of CustomTask)() With { _
New CustomTask() With { _
.DataItemId = "t1", _
.TaskName = "Task 1", _
.Duration = TimeSpan.FromHours(8), _
.DurationFormat = "Days" _
}, _
New CustomTask() With { _
.DataItemId = "t2", _
.TaskName = "Task 2", _
.Duration = TimeSpan.FromHours(24), _
.Predecessors = "t1", _
.DurationFormat = "ElapsedDays" _
}, _
New CustomTask() With { _
.DataItemId = "t3", _
.TaskName = "Task 3", _
.Duration = TimeSpan.FromHours(8), _
.Predecessors = "t2", _
.DurationFormat = "Days" _
}, _
New CustomTask() With { _
.DataItemId = "t4", _
.TaskName = "Task 4", _
.Duration = TimeSpan.FromHours(48), _
.Predecessors = "t3", _
.DurationFormat = "ElapsedDays" _
}, _
New CustomTask() With { _
.DataItemId = "t5", _
.TaskName = "Task 5", _
.Duration = TimeSpan.FromDays(1), _
.Predecessors = "t4", _
.DurationFormat = "Days" _
}, _
New CustomTask() With { _
.DataItemId = "t6", _
.TaskName = "Task 6", _
.Duration = TimeSpan.FromDays(1), _
.Predecessors = "t5", _
.DurationFormat = "ElapsedDays" _
}, _
New CustomTask() With { _
.DataItemId = "t7", _
.TaskName = "Task 7", _
.Duration = TimeSpan.FromHours(8), _
.Predecessors = "t6", _
.DurationFormat = "Days" _
}, _
New CustomTask() With { _
.DataItemId = "t8", _
.TaskName = "Task 8", _
.Duration = TimeSpan.FromHours(8), _
.Predecessors = "t7", _
.DurationFormat = "ElapsedDays" _
} _
}
End Function
#Region "Private helper methods"
Private Function GenerateCustomCalendars() As ObservableCollection(Of CustomCalendar)
Return New ObservableCollection(Of CustomCalendar)() With { _
New CustomCalendar() With { _
.Id = "C1", _
.Name = "Calendar 1", _
.DaysOfWeek = "<ScheduleDaysOfWeek><Monday><ScheduleDayOfWeek><DaySettings><DaySettings IsWorkday=""" /></DaySettings></ScheduleDayOfWeek></Monday><Saturday><ScheduleDayOfWeek><DaySettings><DaySettings IsWorkday=""true""><WorkingHours><WorkingHoursCollection><TimeRange Start=""PT8H"" End=""PT12H"" /><TimeRange Start=""PT13H"" End=""PT17H"" /></WorkingHoursCollection></WorkingHours></DaySettings></DaySettings></ScheduleDayOfWeek></Saturday></ScheduleDaysOfWeek>", _
.CustomDescription = "This custom calendar has a Monday as a nonworking day and Saturday as a working day" _
}, _
New CustomCalendar() With { _
.Id = "C2", _
.Name = "Calendar 2", _
.DaysOfWeek = "<ScheduleDaysOfWeek><Monday><ScheduleDayOfWeek><DaySettings><DaySettings IsWorkday=""true""><WorkingHours><WorkingHoursCollection><TimeRange Start=""PT7H"" End=""PT11H"" /><TimeRange Start=""PT12H"" End=""PT16H"" /></WorkingHoursCollection></WorkingHours></DaySettings></DaySettings></ScheduleDayOfWeek></Monday><Tuesday><ScheduleDayOfWeek><DaySettings><DaySettings IsWorkday=""true""><WorkingHours><WorkingHoursCollection><TimeRange Start=""PT9H"" End=""PT13H"" /><TimeRange Start=""PT14H"" End=""PT18H"" /></WorkingHoursCollection></WorkingHours></DaySettings></DaySettings></ScheduleDayOfWeek></Tuesday><Wednesday><ScheduleDayOfWeek><DaySettings><DaySettings IsWorkday=""true""><WorkingHours><WorkingHoursCollection><TimeRange Start=""PT7H"" End=""PT11H"" /><TimeRange Start=""PT12H"" End=""PT16H"" /></WorkingHoursCollection></WorkingHours></DaySettings></DaySettings></ScheduleDayOfWeek></Wednesday><Thursday><ScheduleDayOfWeek><DaySettings><DaySettings IsWorkday=""true""><WorkingHours><WorkingHoursCollection><TimeRange Start=""PT9H"" End=""PT13H"" /><TimeRange Start=""PT14H"" End=""PT18H"" /></WorkingHoursCollection></WorkingHours></DaySettings></DaySettings></ScheduleDayOfWeek></Thursday><Friday><ScheduleDayOfWeek><DaySettings><DaySettings IsWorkday=""true""><WorkingHours><WorkingHoursCollection><TimeRange Start=""PT7H"" End=""PT11H"" /><TimeRange Start=""PT12H"" End=""PT16H"" /></WorkingHoursCollection></WorkingHours></DaySettings></DaySettings></ScheduleDayOfWeek></Friday></ScheduleDaysOfWeek>", _
.CustomDescription = "This custom calendar sets the following working times: From 9:00to 13:00 and from 14:00 to 18:00" _
} _
}
End Function
#End Region
#Region "INotifyPropertyChanged"
Public Event PropertyChanged As PropertyChangedEventHandler
Public Sub OnPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
#End Region
End Class
このトピックについては、以下のトピックもあわせてご参照ください。