저는 Windows 8 Metro 스타일 앱을 보유하고 있으며 간단한 작업을 수행해야합니다.하지만 해결 방법을 찾는 것이 매우 어렵습니다. 지금 1 주일이 지났지 만 여전히 해결책을 찾지 못했지만, 나는 일하는 해결책을 위해 300 명의 대리점을 제공하고 있습니다.사용자가 MessageDialog에서 단추를 클릭 할 때 FileSavePicker를 호출하는 방법은 무엇입니까?
시나리오 :
내가 텍스트 상자를 편집하고 새 문서 만들기를 클릭
하는 MessageDialog 나는 새를 작성하기 전에 기존 파일에 변경 사항을 저장할지 묻는 나타납니다. "예, 변경 사항 저장"을 클릭하면 FileSavePicker가 열리고 파일을 저장할 수 있습니다.문제 : "예, 변경 사항 저장"을 클릭하면 ACCESSDENIED 예외가 발생합니다. 중단 점을 설정했지만 예외 세부 사항은 다른 정보를 공개하지 않았습니다.
Notes :이 경우에는 요구 사항이 아니기 때문에 DocumentsLibrary 선언을 사용할 수 없으며 작동하지 않을 때 어쨌든 사용하도록 설정했기 때문에 오류가 발생했습니다.
또한 코드는 모두 완벽하게 작동하지만 (서로 분리되어 있음), 모두 묶어서 FileSavePicker를 열려고하면 분리됩니다.
저는 이것이 스레딩 문제 일 수 있다고 생각합니다. 그러나 나는 확실하지 않다.
MessageDialog (MSDN)
async private void New_Click(object sender, RoutedEventArgs e)
{
if (NoteHasChanged)
{
// Prompt to save changed before closing the file and creating a new one.
if (!HasEverBeenSaved)
{
MessageDialog dialog = new MessageDialog("Do you want to save this file before creating a new one?",
"Confirmation");
dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(this.CommandInvokedHandler)));
dialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler(this.CommandInvokedHandler)));
dialog.Commands.Add(new UICommand("Cancel", new UICommandInvokedHandler(this.CommandInvokedHandler)));
dialog.DefaultCommandIndex = 0;
dialog.CancelCommandIndex = 2;
// Show it.
await dialog.ShowAsync();
}
else { }
}
else
{
// Discard changes and create a new file.
RESET();
}
}
그리고 FileSavePicker 물건 :
내가 가진 코드는 다음과 같습니다
private void CommandInvokedHandler(IUICommand command)
{
// Display message showing the label of the command that was invoked
switch (command.Label)
{
case "Yes":
MainPage rootPage = this;
if (rootPage.EnsureUnsnapped())
{
// Yes was chosen. Save the file.
SaveNewFileAs();
}
break;
case "No":
RESET(); // Done.
break;
default:
// Not sure what to do, here.
break;
}
}
async public void SaveNewFileAs()
{
try
{
FileSavePicker saver = new FileSavePicker();
saver.SuggestedStartLocation = PickerLocationId.Desktop;
saver.CommitButtonText = "Save";
saver.DefaultFileExtension = ".txt";
saver.FileTypeChoices.Add("Plain Text", new List<String>() { ".txt" });
saver.SuggestedFileName = noteTitle.Text;
StorageFile file = await saver.PickSaveFileAsync();
thisFile = file;
if (file != null)
{
CachedFileManager.DeferUpdates(thisFile);
await FileIO.WriteTextAsync(thisFile, theNote.Text);
FileUpdateStatus fus = await CachedFileManager.CompleteUpdatesAsync(thisFile);
//if (fus == FileUpdateStatus.Complete)
// value = true;
//else
// value = false;
}
else
{
// Operation cancelled.
}
}
catch (Exception exception)
{
Debug.WriteLine(exception.InnerException);
}
}
가 어떻게이 작업을 얻을 수 있나요?
내 대답이 만족 스럽다면, 현상금 마감을 고려하십시오. – Mir
@Eve 나는 이미 그렇게했다고 생각했습니다. 미안합니다. – Arrow
완료. 다시 한 번 감사드립니다 :) – Arrow