2014-12-03 56 views
1

我无法将自定义类型添加到FileOpenPicker中的ContinuationData中。我可以添加字符串/ int/datetime,但是当我尝试添加我的自定义CustomFolder对象时,它会失败,并出现以下异常。FileOpenPicker:无法将复杂类型添加到ContinuationData

CustomFolder TargetFolde = new CustomFolder() 
FileOpenPicker open = new FileOpenPicker(); 
open.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
open.ViewMode = PickerViewMode.Thumbnail; 

// Filter to include a sample subset of file types 
open.FileTypeFilter.Clear(); 
open.FileTypeFilter.Add(".bmp"); 
open.FileTypeFilter.Add(".png"); 
open.FileTypeFilter.Add(".jpeg"); 
open.FileTypeFilter.Add(".jpg"); 

KeyValuePair<string, object> fold = new KeyValuePair<string, object>("Folder", TargetFolder); 
open.ContinuationData.Add(fold); 
open.PickMultipleFilesAndContinue(); 
} 

{System.Exception的:不支持这种类型的数据。在 System.Runtime.InteropServices.WindowsRuntime.IMap _this,K键,V值)System.Runtime.InteropServices.WindowsRuntime.MapToDictionaryAdapter.Add [K,V](K :(0x8007065E异常来自 HRESULT)键值,V值)在 System.Runtime.InteropServices.WindowsRuntime.MapToCollectionAdapter.Add Lockie.Shared.Util.d__1b.MoveNext()的[K,V](KeyValuePair`2 item) ---堆栈结束追踪从以前的位置,其中的例外是在System.Ru在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification抛出---在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)(任务 任务) ntime.CompilerServices.TaskAwaiter.GetResult()
在Lockie.Folder.d__5.MoveNext()}

+2

CustomFolder类是否声明为可序列化? – Jogy 2014-12-03 22:34:25

+0

我试着用[Serializable接口] ATTRIB使其但是类生活在一个便携式类库不支持此属性。 – 2014-12-03 23:40:24

回答

1

只有基本类型是允许的。 WinRT不提供像.NET一样的序列化机制。您可以使用XML或JSON自己序列化数据,并将其作为字符串存储。

相关问题