xamSchedule を弄ってみる(その3)

前日前々日に引き続き、本日も 「xamSchedule」 ネタを取り上げたいと思います。

CodeZine のInfragistics・池原さんの記事

参考記事: Silverlight/WPFでデータバインディングを利用しOutlookライクなスケジュールを構築する その1 Silverlight編

では取り上げられてませんでしたが、予定の「件名」・「場所」・「コメント」を設定したいというニーズがありますよね。手動で行うには、予定をクリックすると編集ダイアログが起動するので、こちらで設定可能です。


では、手動でなくプログラミングで予定の件名を設定するにはどうすればいいか?調べたところ、予定の実体はどうやら Infragistics.Controls.Schedules.Appointment クラスのようです。これのヘルプを見ると以下のプロパティが確認できました。

名前 解説
Description このアクティビティに関連付けられたテキストを取得または設定します。
Location 予定の位置を取得または設定します。
Subject このアクティビティに関連付けられた題名を取得または設定します。


要するに、Description がコメント、Locationが場所、Subjectが件名のようです。ではこれらのプロパティを予定用のデータクラスである AppointmentInfo に追加してみます。AppointmentInfo の実装の詳細については、CodeZineの記事を参考にしてください。

// C#(AppointmentInfo.cs)
using System;

namespace ScheduleDataViewModel
{
    public class AppointmentInfo : ViewModelBase
    {
        #region プロパティ

        ・・・・中略・・・・

        private string _Description;
        public string Description
        {
            get { return _Description; }
            set
            {
                _Description = value;
                OnPropertyChanged("Description");
            }
        }

        private string _Location;
        public string Location
        {
            get { return _Location; }
            set
            {
                _Location = value;
                OnPropertyChanged("Location");
            }
        }

        private string _Subject;
        public string Subject
        {
            get { return _Subject; }
            set
            {
                _Subject = value;
                OnPropertyChanged("Subject");
            }
        }
        #endregion
    }
}
' Visual Basic(AppointmentInfo.vb)
Option Explicit On
Option Strict On

Imports System
Imports Livet

Public Class AppointmentInfo
    Inherits ViewModelBase

#Region "プロパティ"

    ・・・・中略・・・・

    Private _Description As String
    Public Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            _Description = value
            OnPropertyChanged("Description")
        End Set
    End Property

    Private _Location As String
    Public Property Location() As String
        Get
            Return _Location
        End Get
        Set(ByVal value As String)
            _Location = value
            OnPropertyChanged("Location")
        End Set
    End Property

    Private _Subject As String
    Public Property Subject() As String
        Get
            Return _Subject
        End Get
        Set(ByVal value As String)
            _Subject = value
            OnPropertyChanged("Subject")
        End Set
    End Property
#End Region

End Class


MainPageViewModel(WPF の場合 MainWindowViewModel) のコンストラクタ内の「予定を追加」する部分を以下のように変更します。

// C#(MainPageViewModel.cs/MainWindowViewModel.cs)

// 予定を追加
Appointments = new ObservableCollection<AppointmentInfo>();
Appointments.Add(new AppointmentInfo()
{
     Id = "A0001",
     OwningCalendarId = "C0001",
     OwningResourceId = "R0001",
     Start = DateTime.Now.ToUniversalTime(),
     End = DateTime.Now.AddHours(2).ToUniversalTime(),
     Description = "時間厳守!入場は業者専用口からお願いします",
     Location = "東京都千代田区",
     Subject = "電通"
});
' Visual Basic(MainPageViewModel.vb/MainWindowViewModel.vb)

' 予定を追加
Me.Appointments = New ObservableCollection(Of AppointmentInfo)()
Me.Appointments.Add(
    New AppointmentInfo() With {
        .Id = "A0001",
        .OwningCalendarId = "C0001",
        .OwningResourceId = "R0001",
        .Start = DateTime.Now.ToUniversalTime(),
        .End = DateTime.Now.AddHours(2).ToUniversalTime(),
        .Description = "時間厳守!入場は業者専用口からお願いします",
        .Location = "東京都千代田区",
        .Subject = "電通"
    }
)


以下、実行画面(WPF)です。


ここで疑問がひとつ生じます。予定にバインドするクラスは Appointment クラスとプロパティ名が同じでないといけないのかと・・・これを解決するのが「データマッピングの指定」ですね。当初、サンプルの XAML 内でなぜ各PropertyMappingCollection.UseDefaultMappings を True にしなければならないか判らなかったのですが、段々判ってまいりました (^ ^)v
データマッピングについては、また機会あれば取り上げたいと思います。