2
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命名空间

Class 太奇怪了StoredContact

有谁能够帮我!这个怎么设置KnownContactProperties.Birthdate

4

1 回答 1

5

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

尝试这个:

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

问候。

于 2013-01-29T15:08:51.630 回答