Tombstone wp7 how save Enum... and other unkwon object
When I save a variable that containing an Enum type in wp7 (C#) I receive an Exception, the meaning is that enum is a not known type so the system cannot serialize.
for开发者_运维技巧 example
public enum videoType:int {
LongVideo=1,
ShortVideo }
or
public enum video
{
LongVideo,ShortVideo
}
_videoType = videoType.ShortVideo
PhoneApplicationService.Current.State["myType"]
someone tell me to use Datacontract and data member but seems not available in wp7
so how save a enum type?
You will have to save the Enum Value as integer and reset to correct Enum value from the integer after the page gets activated.
[Read back the saved integer value and set the correct enum value. Lookup Enum.Parse/Enum.TryParse]
Also you can have a look at the EnumValueToDescription Converter attribute implemented by Josh Smith in his article here http://www.codeproject.com/KB/WPF/WPFJoshSmith.aspx?msg=3766336 [WPF]
http://www.michaelsnow.com/2010/12/25/how-to-convert-an-enum-to-its-string-value/
DataContract and DataMember most definitely are available in all versions of WP7.
You do not need to specify int as the ancestor type because int is the default ancestor type.
public enum videoType
{
LongVideo = 1,
ShortVideo,
}
Since you can convert int to an int-based enum with simple cast, I suggest casting as int to save and casting back to your enum to load.
See the answers at: How do I serialize an enum value as an int?
精彩评论