Windows 8.1 Metro应用程序中的本地AppData监视器(StorageFileQueryResult.ContentsChanged事件未触发)

Windows 8.1 Metro应用程序中的本地AppData监视器(StorageFileQueryResult.ContentsChanged事件未触发),windows-8.1,winrt-async,appdata,Windows 8.1,Winrt Async,Appdata,监视器如何处理AppData文件夹中的特定文件 我曾尝试使用StorageFolderQueryResult.ContentsChanged事件来处理此问题,但此事件实际上会回调文件夹中的任何更改 auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>(); fileTypeFilter->Append("*"); auto queryOptions = ref n

监视器如何处理AppData文件夹中的特定文件

我曾尝试使用StorageFolderQueryResult.ContentsChanged事件来处理此问题,但此事件实际上会回调文件夹中的任何更改

     auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append("*");

auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderBySearchRank, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = InputTextBox->Text;
auto queryResult = musicFolder->CreateFileQueryWithOptions(queryOptions);


auto localFolder = ApplicationData::Current->LocalFolder;
auto currPath = localFolder->Path;
auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append(".dat");

auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderByName, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = L"filename";
auto queryResult = localFolder->CreateFileQueryWithOptions(queryOptions);
queryResult->ContentsChanged += ref new TypedEventHandler<IStorageQueryResultBase^,        Platform::Object^>(this, &Scenario1::OnLocalAppDataChanged);
     //find all files that match the query
 create_task(queryResult->GetFilesAsync()).then([this, queryOptions]    (IVectorView<StorageFile^>^ files)
    {
        String^ outputText = "";
        //output how many files that match the query were found
        if ( files->Size == 0)
     {
         outputText += "No files found for '" + queryOptions->UserSearchFilter + "'";
    }
    else if (files->Size == 1)
    {
        outputText += files->Size.ToString() + " file found:\n\n";
    }
    else
    {
        outputText += files->Size.ToString() + " files found:\n\n";
    }
    //output the name of each file that matches the query
    for (unsigned int i = 0; i < files->Size; i++)
    {
        outputText += files->GetAt(i)->Name + "\n";
    }
    OutputTextBlock->Text = outputText;
});
}
void Scenario1::OnLocalAppDataChanged(Windows::Storage::Search::IStorageQueryResultBase^ sender, Platform::Object^ args)
{
Platform::String^ hello = L"hello world, I'm called back";
}
我的问题是只监视单个文件,并在其更改时使用eventhandler

我尝试使用这个“UserSearchFilter”属性来查询选项。那实际上不起作用

有人能帮忙吗?如果您可以另外提供整个问题的语法,这也会很有帮助

修改文件夹中的“文件名”时未触发My contentschanged事件

     auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append("*");

auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderBySearchRank, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = InputTextBox->Text;
auto queryResult = musicFolder->CreateFileQueryWithOptions(queryOptions);


auto localFolder = ApplicationData::Current->LocalFolder;
auto currPath = localFolder->Path;
auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append(".dat");

auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderByName, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = L"filename";
auto queryResult = localFolder->CreateFileQueryWithOptions(queryOptions);
queryResult->ContentsChanged += ref new TypedEventHandler<IStorageQueryResultBase^,        Platform::Object^>(this, &Scenario1::OnLocalAppDataChanged);
     //find all files that match the query
 create_task(queryResult->GetFilesAsync()).then([this, queryOptions]    (IVectorView<StorageFile^>^ files)
    {
        String^ outputText = "";
        //output how many files that match the query were found
        if ( files->Size == 0)
     {
         outputText += "No files found for '" + queryOptions->UserSearchFilter + "'";
    }
    else if (files->Size == 1)
    {
        outputText += files->Size.ToString() + " file found:\n\n";
    }
    else
    {
        outputText += files->Size.ToString() + " files found:\n\n";
    }
    //output the name of each file that matches the query
    for (unsigned int i = 0; i < files->Size; i++)
    {
        outputText += files->GetAt(i)->Name + "\n";
    }
    OutputTextBlock->Text = outputText;
});
}
void Scenario1::OnLocalAppDataChanged(Windows::Storage::Search::IStorageQueryResultBase^ sender, Platform::Object^ args)
{
Platform::String^ hello = L"hello world, I'm called back";
}
auto-fileTypeFilter=ref新平台::集合::向量();
fileTypeFilter->追加(“*”);
自动查询选项=引用新查询选项(CommonFileQuery::OrderBySearchRank,fileTypeFilter);
//使用用户的输入进行查询
查询选项->用户搜索过滤器=输入文本框->文本;
自动查询结果=musicFolder->CreateFileQueryWithOptions(查询选项);
auto localFolder=ApplicationData::Current->localFolder;
自动currPath=localFolder->Path;
自动fileTypeFilter=ref新平台::集合::向量();
fileTypeFilter->Append(“.dat”);
自动查询选项=引用新查询选项(CommonFileQuery::OrderByName,fileTypeFilter);
//使用用户的输入进行查询
queryOptions->UserSearchFilter=L“文件名”;
auto queryResult=localFolder->CreateFileQueryWithOptions(查询选项);
queryResult->ContentsChanged+=ref新类型deventhandler(此,&Scenario1::OnLocalAppDataChanged);
//查找与查询匹配的所有文件
创建任务(queryResult->GetFileAsync())。然后([这个,queryOptions](IVectorView^文件)
{
字符串^outputText=“”;
//输出找到的与查询匹配的文件数
如果(文件->大小==0)
{
outputText+=“未找到'”+queryOptions->UserSearchFilter+“'的文件”;
}
else if(文件->大小==1)
{
outputText+=文件->大小.ToString()+“找到文件:\n\n”;
}
其他的
{
outputText+=文件->大小.ToString()+“找到的文件:\n\n”;
}
//输出与查询匹配的每个文件的名称
对于(无符号整数i=0;iSize;i++)
{
outputText+=files->GetAt(i)->Name+“\n”;
}
OutputExtBlock->Text=输出文本;
});
}
void Scenario1::OnLocalAppDataChanged(Windows::Storage::Search::IStorageQueryResultBase^发件人,平台::对象^args)
{
平台::字符串^hello=L“你好,世界,我被叫回来了”;
}

必须至少调用一次getFileAsync()方法,否则事件将永远不会触发

以前

queryResult->ContentsChanged += ref new TypedEventHandler<IStorageQueryResultBase^,...
queryResult->ContentsChanged+=ref新类型deventhandler