none
String转ApplicationDataCompositeValue报错 RRS feed

  • 问题

  • System.InvalidCastException:“Unable to cast object of type 'System.String' to type 'Windows.Storage.ApplicationDataCompositeValue'.”
    2018年4月5日 3:18

全部回复

  • 后者是一个字典对象,与String类型转化需要定义converter才可以

    https://docs.microsoft.com/en-us/uwp/api/Windows.Storage.ApplicationDataCompositeValue

    Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
    
    // Create a composite setting
    
    Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();
    composite["intVal"] = 1;
    composite["strVal"] = "string";
    
    localSettings.Values["exampleCompositeSetting"] = composite;
    
    // Read data from a composite setting
    
    Windows.Storage.ApplicationDataCompositeValue composite = 
       (Windows.Storage.ApplicationDataCompositeValue)localSettings.Values["exampleCompositeSetting"];
    
    if (composite == null)
    {
       // No data
    }
    else
    {
       // Access data in composite["intVal"] and composite["strVal"]
    }
    
    // Delete a composite setting
    
    localSettings.Values.Remove("exampleCompositeSetting");


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2018年4月8日 0:50