10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WPFのDatePickerで年月入力

Last updated at Posted at 2015-07-30

#はじめに
DatePickerで年月を選択させたいと考え調査した。
WinFormのDateTimePicerを使えば簡単に実現できるがBindができない。
Livetを使うのであれば、標準のDatePickerのほうがよい。
海外のページに「WPF Toolkit DatePicker Month/Year Only」を見つけた。ここの、#3のAnserが良いと思い投稿する。

#イメージ
下図のように月が選択できるようになり、入力しやすくなっている。
DatePickerイメージ.png

xamlでの指定

<DatePicker Control:DatePickerCalender.IsMonthYear="True"
            Control:DatePickerDateFormat.DateFormat="yyyy/MM"
            SelectedDate="{Binding 年月}"/>

#Usingの指定
上記リンクのソースをそのまま利用すると動作するようになるが、Usingが必要になる。
Usingで時間がかかったので下記に記す。

DatePickerCalendar
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Threading;
DatePickerDateFormat
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
10
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?