2017-03-12 1 views
-3

현재 Windows 범용 프로젝트에서 격리 된 저장소를 구현하는 방법을 찾는 데 어려움이 있습니다.UWP 격리 된 저장소 사용 방법

격리 된 저장소를 사용하는 방법에 대한 좋은 답변이나 자습서를 온라인에서 찾았습니다. 기본적으로 내가하고 싶은 것은 단추를 클릭 할 때 격리 된 저장소의 일부 텍스트를 안전하게 유지하고 나중에이를 검색 할 수있게하는 것입니다. 사용할 다른 페이지.

답변

1

일부 프리미티브 개체를 저장할 수있는 사전으로 ApplicationData.Current.LocalSettings을 사용할 수 있습니다.

ApplicationData.Current.LocalSettings.Values["MyKey"] = MyValue; 

if (ApplicationData.Current.LocalSettings.Values.ContainsKey("MyKey")) 
    MyValue = ApplicationData.Current.LocalSettings.Values["MyKey"]; 
+0

? 이전 WP7 IsolatedStorage와 유사합니다. –

+0

이 시도했지만 로컬 설정 값을 포함하지 않는 오류가 계속 – user7629970

1

앱 데이터를 UWP에 로컬로 저장할 수 있습니다 (예 : UWP). ApplicationData.Current.LocalFolder, 그리고 이것은 '고립 된 저장소'에 대한 이야기입니다. 여기 당신을위한 코드 예제는 다음과 같습니다

//Create dataFile.txt in LocalFolder and write “My text” to it 
StorageFolder localFolder = ApplicationData.Current.LocalFolder; 
StorageFile sampleFile = await localFolder.CreateFileAsync("dataFile.txt"); 
await FileIO.WriteTextAsync(sampleFile, "My text"); 

//Read the first line of dataFile.txt in LocalFolder and store it in a String 
StorageFile sampleFile = await localFolder.GetFileAsync("dataFile.txt"); 
String fileContent = await FileIO.ReadTextAsync(sampleFile); 

또한 자세한 내용은 여기를 볼 수 있습니다 당신은 격리 된 저장소에서 무엇을 의미합니까 Getting started storing app data locally

+0

여러 줄을 읽으려면 반복해야합니까? 내가 글을 쓸 때마다 새로운 라인에 저장 될까요? – user7629970

+0

'FileIO.ReadTextAsync' 메소드는 파일의 전체 내용을 반환 할 것이고,'FileIO.WriteTextAsync'는 대상 파일이 이미 존재한다면 내용을 덮어 쓸 것입니다. 위의 코드는 참고 용일뿐입니다. 필요에 따라 코드를 올바르게 작성해야합니다. – WPInfo

+0

@WPInfo 파일의 헤더에 줄을 추가하는 방법. – lindexi