WP8 KnownContactProperties.Birthdate无法设置值

时间:2013-01-17 09:55:45

标签: c# windows-phone

var store = await ContactStore.CreateOrOpenAsync();
StoredContact sc = new StoredContact(store);
IDictionary<string, object> values = await sc.GetPropertiesAsync();
values[KnownContactProperties.FamilyName] =  "bbb";
values[KnownContactProperties.GivenName]=  "worerrrrld";

//*************problem here**************
Nullable<DateTime> birth = DateTime.Now;
values[KnownContactProperties.Birthdate] = birth;
//values[KnownContactProperties.Birthdate] = DateTime.Now;
//values[KnownContactProperties.Birthdate] = "2010-05-10";
//it will cause exception by any way above.
//***************************************

await sc.SaveAsync();//Exception throw here  :System.InvalidCastException

关于windows phone8 API

Windows.Phone.PersonalInformation命名空间

关于班级StoredContact太奇怪了!

任何身体都可以帮助我!如何设置此KnownContactProperties.Birthdate

1 个答案:

答案 0 :(得分:5)

InvalidCastException是正常的,因为预期的对象是DateTimeOffset。

试试这个:

values[KnownContactProperties.Birthdate] = new DateTimeOffset(DateTime.Parse("2010-05-10"));

问候。