?この手順では、アプリケーションにコードを追加して、連絡先の追加を処理し、指定された日の VisualIntervalCollection を返すように制御します。
MainPage.xaml を右クリックし、リストから[コードの表示]を選択します。
次の名前空間をアプリケーションに追加します。
Visual Basic |
コードのコピー
|
---|---|
Imports C1.C1Schedule Imports C1.WPF.Schedule Imports C1.WPF Imports System.Collections |
C# |
コードのコピー
|
---|---|
using C1.C1Schedule; using C1.WPF.Schedule; using C1.WPF; using System.Collections; |
InitializeComponent() メソッドのすぐ下に、次のコードを挿入します。
Visual Basic |
コードのコピー
|
---|---|
' 連絡先を追加します Dim cnt As New Contact() cnt.Text = "Andy Garcia" c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt) cnt = New Contact() cnt.Text = "Nancy Drew" c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt) cnt = New Contact() cnt.Text = "Robert Clark" c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt) cnt = New Contact() cnt.Text = "James Doe" c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt) c1Scheduler1.GroupBy = "Contact" |
C# |
コードのコピー
|
---|---|
// 連絡先を追加します Contact cnt = new Contact(); cnt.Text = "Andy Garcia"; c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt); cnt = new Contact(); cnt.Text = "Nancy Drew"; c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt); cnt = new Contact(); cnt.Text = "Robert Clark"; c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt); cnt = new Contact(); cnt.Text = "James Doe"; c1Scheduler1.DataStorage.ContactStorage.Contacts.Add(cnt); c1Scheduler1.GroupBy = "Contact"; |
次のコードは、指定された日の VisualIntervalCollection と SchedulerGroup を返します。
Visual Basic |
コードのコピー
|
---|---|
''' <summary> ''' 指定された日の VisualIntervalCollection と、指定された SchedulerGroup を返します。これは、VisualIntervalsPresenter ''' コントロールの ItemsSource として使用されます。 ''' </summary> ''' <remarks> ''' コンバータパラメータが "Self" の場合は、全日領域を表すための ItemsSource として使用される、1つの VisualIntervalGroup から成るリストを返します。 ''' その他の場合は、1日のタイムスロットを含む VisualItervalCollection を返します。 ''' </remarks> Public Class GroupItemToVisualIntervalsConverter Implements IValueConverter Public Shared [Default] As New GroupItemToVisualIntervalsConverter() #Region "IValueConverter Members" Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert Dim el As FrameworkElement = TryCast(value, FrameworkElement) If el IsNot Nothing Then Dim group As SchedulerGroupItem = TryCast(el.DataContext, SchedulerGroupItem) Dim index As Integer = -1 If group IsNot Nothing Then Dim itm As ItemsControl = TryCast(VTreeHelper.GetParentOfType(el, GetType(ItemsControl)), ItemsControl) If itm IsNot Nothing Then Dim data As Object = itm.DataContext Dim itmParent As ItemsControl = TryCast(VTreeHelper.GetParentOfType(itm, GetType(ItemsControl)), ItemsControl) If itmParent IsNot Nothing Then index = itmParent.Items.IndexOf(data) Dim visualIntervalGroup As VisualIntervalGroup = TryCast(group.VisualIntervalGroups(index), VisualIntervalGroup) Dim param As String = CStr(parameter) If param.ToLower() = "self" Then ' 1つの VisualIntervalGroup から成るリストを作成します ' (これを ItemsSource として使用する必要があります) Dim list As New List(Of Object)() list.Add(visualIntervalGroup) Return list Else Return visualIntervalGroup.VisualIntervals End If End If End If End If End If Return Nothing End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack Throw New NotImplementedException() End Function #End Region End Class End Namespace |
C# |
コードのコピー
|
---|---|
/// <summary> /// 指定された日の VisualIntervalCollection と、指定された SchedulerGroup を返します。これは、VisualIntervalsPresenter /// コントロールの ItemsSource として使用されます。 /// </summary> /// <remarks> /// コンバータパラメータが "Self" の場合は、全日領域を表すための ItemsSource として使用される、1つの VisualIntervalGroup から成るリストを返します。 /// その他の場合は、1日のタイムスロットを含む VisualItervalCollection を返します。 /// </remarks> public class GroupItemToVisualIntervalsConverter : IValueConverter { public static GroupItemToVisualIntervalsConverter Default = new GroupItemToVisualIntervalsConverter(); #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { FrameworkElement el = value as FrameworkElement; if (el != null) { SchedulerGroupItem group = el.DataContext as SchedulerGroupItem; int index = -1; if (group != null) { ItemsControl itm = VTreeHelper.GetParentOfType(el, typeof(ItemsControl)) as ItemsControl; if (itm != null) { object data = itm.DataContext; ItemsControl itmParent = VTreeHelper.GetParentOfType(itm, typeof(ItemsControl)) as ItemsControl; if (itmParent != null) { index = itmParent.Items.IndexOf(data); VisualIntervalGroup visualIntervalGroup = group.VisualIntervalGroups[index] as VisualIntervalGroup; string param = (string)parameter; if (param.ToLower() == "self") { // 1つの VisualIntervalGroup から成るリストを作成します // (これを ItemsSource として使用する必要があります) List<object> list = new List<object>(); list.Add(visualIntervalGroup); return list; } else { return visualIntervalGroup.VisualIntervals; } } } } } return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } } |
この手順では、連絡先を作成し、指定された日の VisualIntervalCollections を返すコードを追加しました。次の手順では、リソースディクショナリを作成します。