0

을 파일로 :쓰기 ObservableCollection에 내가 가진 무엇

class Storico 
{ 
    private string rigaStorico; 

    public string Name 
    { 
     get { return rigaStorico; } 
     set { rigaStorico = value; } 
    } 

    public Storico(string storic) 
    { 
     rigaStorico = storic; 
    }  
} 

이 ObservableCollection에 :하십시오 LongListSelector에 위치한

ObservableCollection<Storico> rigaStorico = new ObservableCollection<Storico>(); 

그리고이 DataTemplate을 :

나는 현재이 클래스가

<DataTemplate> 
    <Grid> 
     <TextBlock Text="●" Margin="0,8,0,0" Foreground="#EE7B00"/> 
     <TextBlock Text="{Binding Name}" ManipulationStarted="TextBlock_ManipulationStarted" ManipulationCompleted="TextBlock_ManipulationCompleted"> 
      <toolkit:ContextMenuService.ContextMenu> 
       <toolkit:ContextMenu Name="ContextMenu" > 
        <toolkit:MenuItem Name="DeleteItem" Header="Delete Item" Click="DeleteItem_Click"/> 
       </toolkit:ContextMenu> 
      </toolkit:ContextMenuService.ContextMenu> 
     </TextBlock> 
    </Grid> 
</DataTemplate> 

내가해야 할 일은 :

String1 
String2 
String3 

및 반전에, IsolatedStorage로 파일에 쓰기 등이있다 나는 실제로 LongListSelector에 포함 된 모든 문자열을 필요

을, 주문. 이런 식으로 뭔가 : 나는 내 목표는 명확하고 나는 그것을 해결하기 위해 필요한 모든 물건을 준 희망

Storico.ItemsSource = rigaStorico; 

:

분명히 충분히
String3 
String2 
String1 

의 스토리 코의 ItemsSource는 rigaStorico 자체입니다.

+0

당신이 시도 무엇인지 설명하고있는 대안 구체적인 문제 (또는, 우리는 당신을 청구 할 수있는 은행 데이터 우리 계약직). – SJuan76

+0

나는 실제로 LINQ, String 배열 등으로 놀아 보았습니다. 일단 그들이 성공하지 못했다면 내 시도를 게시하지 말라는 말을 듣고 질문에 아무런 가치도 부여하지 않았습니다. 그게 내가 지금하고있는거야 :) –

답변

0

감사합니다 : 당신은 당신이 단지 수 원하는 경우

FileStorage.WriteSharedData("MyItems.js", rigaStorico.Reverse()); 

는 FileStorage는 후드 json.net 사용합니다. 나는 다음과 같은 코드를 사용하여 내 문제를 해결 :없는 무엇


string[] contenutoStorico = rigaStorico.Select(x => x.Name).ToArray(); 

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("history.txt", FileMode.Create, FileAccess.Write, myIsolatedStorage))) 
{ 
    for (int i = 0; i < contenutoStorico.Length; i++) 
    { 
     writeFile.WriteLine(contenutoStorico[contenutoStorico.Length-i-1]);      
    } 
    writeFile.Close(); 
} 
1

이 시도 :

IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication(); 

IsolatedStorageFileStream fs = null; 
using (fs = savegameStorage.CreateFile("FILENAME")) 
{ 
    if (fs != null) 
    { 
     var index = 0; 
     foreach(var rigaStor in rigaStorico.Reverse()) 
     { 
      byte[] bytes = Encoding.UTF8.GetBytes(rigaStor.Name); 
      fs.Write(bytes, index, bytes.Length); 
      index = bytes.Length; 
     } 
    } 
} 
+0

byte [] bytes = System.BitConverter.GetBytes (rigaStor.Name); 문제를주고 있습니다. GetBytes는 취할 수있는 여러 가지 인수가있는 보고서를 제공합니다. –

+1

@ guido1993 Encoding.UTF8.GetBytes로 변경했습니다. –

+0

이것은 LongListSelector에 하나 또는 두 개의 요소가있을 때 실제로 작동합니다. 내가 3, 또는 더 많은 것을 얻으면, 응용 프로그램은 단지 "NullReferenceException"을 던지면서 충돌합니다. –

1

당신이 역순으로 필요하지만, 당신이 밖으로 데이터를 기록하기 위해이 FileStorage를 사용할 수있는 이유는 확실하지. 도움을

var storage = IsolatedStorageFile.GetUserStoreForApplication(); 
using (var fileStream = storage.CreateFile(fileName)) 
{ 
    //Write the data 
    using (var isoFileWriter = new StreamWriter(fileStream)) 
    { 
     var json = JsonConvert.SerializeObject(rigaStorico.Reverse()); 
     isoFileWriter.WriteLine(json); 
    } 
} 
+0

당신의 솔루션은 효과가 있지만, 결과는 모든 줄과 형식으로 나타납니다. {{ "Name": "str1"}, { "Name": "str2"} ],이 코드를 사용하여 파일에서 읽을 때 : IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile ("history.txt", FileMode.OpenOrCreate, FileAccess.Read); rigaStorico.Insert (0, 새 Storico (reader.ReadLine())); 내 필요에 맞게 코드를 어떻게 변경해야하는지 잘 모르겠습니다. 내 애플 리케이션의 큰 부분을 다시 작성한다는 뜻대로 광산을 유지하고 싶습니다 :) –

+1

FileStorage 클래스를 사용하고 ReadSharedData 메서드를 호출하십시오. 'FileStorage.ReadSharedData > (history.txt ");' –