WP8 KnownContactProperties.Birthdate can not set value

筅森魡賤 提交于 2019-12-11 03:22:08

问题


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

About windows phone8 API

Windows.Phone.PersonalInformation namespace

It's too weird about Class StoredContact!

Can any body help me! How to set this KnownContactProperties.Birthdate?


回答1:


The InvalidCastException is normal since the expected object is DateTimeOffset.

Try this:

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

Regards.



来源:https://stackoverflow.com/questions/14376342/wp8-knowncontactproperties-birthdate-can-not-set-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!