1

我知道我可以通过RetrievePropertiesAsync()方法检索文件的预定义属性。但是现在我想再添加一个我自己的自定义属性,比如描述,有可能吗?我试过这段代码,但得到异常

protected async override void OnNavigatedTo(NavigationEventArgs e)
{
    StorageFile file = await KnownFolders.MusicLibrary.GetFileAsync("video.mp4");
    List<string> propertiesName = new List<string>();
    propertiesName.Add("CustomProperty");
    string a = "Come and knock on our door. We've been waiting for you. Where the kisses are hers and hers and his, three's company, too! Come and dance on our floor. Take a step that is new. We've a lovable space that needs your face, three's company, too! You'll see that life is a ball again and laughter is callin' for you. Down at our rendezvous, three's company, too! The year is 1987 and NASA launches the last of America's deep space probes. In a freak mishap, Ranger 3 and its pilot Captain William 'Buck' Rogers are blown out of their trajectory into an orbit which freezes his life support system and returns Buck Rogers to Earth five hundred years later.";
    IDictionary<string, object> extraProperties = await file.Properties.RetrievePropertiesAsync(propertiesName);
    extraProperties.Add((new KeyValuePair<string, object>("CustomProperty", a)));
    await file.Properties.SavePropertiesAsync(extraProperties);
}

An exception of type 'System.ArgumentException' occurred in App2.exe but was not handled in user code
WinRT information: The specified property name (CustomProperty) is invalid. The property may not be registered on the system.
Additional information: The parameter is incorrect.

PS:我想要这样的东西

4

1 回答 1

1

这些错误似乎表明需要在要检索的属性系统中定义该属性。快速 MSDN 搜索显示它可以使用PSRegisterPropertySchema 函数完成,但它仅适用于桌面应用程序。 本主题更详细地描述了注册自定义属性。由于 Windows 8 中已经有很多内置属性和 WinRT,因为它专注于基础知识,因此不太可能从 Windows 应用商店应用程序中实现。这意味着您可以使用桌面应用程序注册该属性,但如果要通过认证,您的商店应用程序不能依赖它的存在。StorageItemContentProperties的文档提到使用 QueryOptions 来查询由其他应用程序定义的属性,如果您想搜索由其他一些应用程序定义的属性,您可以尝试使用它。

注意使用由另一个应用程序(如 Microsoft Word)定义的属性处理程序获取或设置的属性可能无法访问。相反,您可以尝试使用由系统索引支持的文件查询来获取这些属性。有关详细信息,请参阅 QueryOptions

于 2012-09-29T05:10:46.157 回答