最初的目标是在ApplicationData::Current->RoamingSettings
中存储颜色,但由于“值”容器是IPropertySet
,因此我可以存储的类型受限制。
所以,我使用Array<unsigned char, 1U>^
来存储RGBA值,如下所示:
ApplicationDataContainer^ roamingSettings = ApplicationData::Current->RoamingSettings;
Color black = Colors::Black;
Array<unsigned char, 1U>^ rgbaIn = ref new Array<unsigned char, 1U>{ black.R, black.G, black.B, black.A };
roamingSettings->Values->Insert("colourArr", PropertyValue::CreateUInt8Array(rgbaIn));
//String for control reasons
roamingSettings->Values->Insert("colourStr", PropertyValue::CreateString(ref new String(L"black")));
Array<unsigned char, 1U>^ rgbaOut = dynamic_cast<Array<unsigned char, 1U>^>(roamingSettings->Values->Lookup("colourArr"));
String^ colour = dynamic_cast<String^>(roamingSettings->Values->Lookup("colourStr"));
此时,rgbaOut
是空数组,而colour
的值为"black"
。
为什么?我该怎么做才能解决这个问题?
我应该提一下rgbaIn
是正确构造的,确实包含正确的四个值。