[UWP] [C ++]如何枚举存储在ApplicationDataComposite中的信息? [英] [UWP][C++] How to enumerate info stored in ApplicationDataComposite ?
问题描述
我的UWP C ++应用程序使用ApplicationDataComposite存储客户名称列表,如下所示。
My UWP C++ app store the list of customer's name using ApplicationDataComposite as codes below.
在应用程序启动期间,应用程序需要枚举与客户信息(地址,电话等)相关联的客户名称列表。我怎么能这样做?是否有任何UWP C ++示例代码来完成这项任务?
During application startup, the app needs to enumerate the list of customer's name associated with customer information (address, phone, etc...). How could I do that ? are there any UWP C++ sample codes to achieve this task ?
谢谢
void MainPage :: OnSaveCustomerInfoBtn_Click(Platform :: Object ^ sender,Windows :: UI :: Xaml :: RoutedEventArgs ^ e)
{
composite = safe_cast< ApplicationDataCompositeValue ^>(localSettings-> Values-> Lookup(customerName-> Text));
if composite == nullptr){
composite = ref new ApplicationDataCompositeValue();
auto values = localSettings->值;
values-> Insert(customerName-> Text,composite);
}
composite-> Insert(" address",dynamic_cast< PropertyValue ^>(PropertyValue :: CreateString(customerAddress-> Text)));
composite-> Insert(" phone",dynamic_cast< PropertyValue ^>(PropertyValue :: CreateString(customerPhone-> Text)));
}
void MainPage::OnSaveCustomerInfoBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
composite = safe_cast<ApplicationDataCompositeValue^>(localSettings->Values->Lookup(customerName->Text));
if composite == nullptr) {
composite = ref new ApplicationDataCompositeValue();
auto values = localSettings->Values;
values->Insert(customerName->Text, composite);
}
composite->Insert("address", dynamic_cast<PropertyValue^>(PropertyValue::CreateString(customerAddress->Text)));
composite->Insert("phone", dynamic_cast<PropertyValue^>(PropertyValue::CreateString(customerPhone->Text)));
}
推荐答案
嗨dalee,
您可以参考以下内容代码段。此外,您可以通过创建ApplicationDataContainer来组织数据。有关详细信息,请参阅此处。
https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdatacontainer.aspx
auto values = localSettings->Values;
for (auto compositeCollection : values)
{
auto name = compositeCollection->Key;
auto composite = safe_cast<ApplicationDataCompositeValue^>(compositeCollection->Value);
auto address = safe_cast<String^>(composite->Lookup("address"));
}
最好的问候,
David
Best Regards,
David
这篇关于[UWP] [C ++]如何枚举存储在ApplicationDataComposite中的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!