WP8 KnownContactProperties.Birthdate不能设置值 [英] WP8 KnownContactProperties.Birthdate can not set value

查看:110
本文介绍了WP8 KnownContactProperties.Birthdate不能设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

phone8 API

About windows phone8 API

Windows.Phone.PersonalInformation 命名空间

对于 StoredContact

可以任何身体帮助我太奇怪了!如何设置 KnownContactProperties.Birthdate

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

推荐答案

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

The InvalidCastException is normal since the expected object is DateTimeOffset.

请尝试以下操作:

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

回答。

这篇关于WP8 KnownContactProperties.Birthdate不能设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆