作成日: 2017/12/19 最終更新日: 2017/12/19
文書種別
使用方法
詳細
Calendarが日付領域を作成する際のイベントであるDaySlotLoadingで画像を設定すれば、日付領域に画像が設定できます。日付や曜日で判断し、それぞれに対応した画像を設定することも可能です。
サンプルコード
C#(Xamarin.Forms)
サンプルコード
C#(Xamarin.Forms)
public MainPage()
{
InitializeComponent();
// 日付スロットの処理
calendar.DaySlotLoading += (sender, e) =>
{
// 当月カレンダーの処理(前後の月に隣接する日ではない)
if (!e.IsAdjacentDay)
{
// 日付領域に表示する内容を設定
var grid = new Grid();
grid.RowDefinitions = new RowDefinitionCollection{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star }
};
var label = new Label();
label.Text = e.Date.Day.ToString() + "日";
grid.Children.Add(label, 0, 0);
var image = new Image();
image.Source = getImage(e.Date.DayOfWeek);
image.Aspect = Aspect.AspectFit;
grid.Children.Add(image, 0, 1);
e.DaySlot = grid;
}
};
}
// 曜日で判断して画像を設定する関数
private ImageSource getImage(System.DayOfWeek dayofWeek)
{
ImageSource imagesource = null;
switch (dayofWeek)
{
case System.DayOfWeek.Tuesday: // 火曜日
imagesource = ImageSource.FromResource("C1CalendarCustom.Images.trashcan.png", Assembly.GetExecutingAssembly());
break;
case System.DayOfWeek.Friday: // 金曜日
imagesource = ImageSource.FromResource("C1CalendarCustom.Images.trashcan.png", Assembly.GetExecutingAssembly());
break;
}
return imagesource;
}
旧文書番号
82477