2015-05-12 82 views
0

嗨我所有的工作都在一個Windows手機聊天應用程序,我已經完成與兩端聊天現在我面臨的問題,當我重新打開我的應用程序我的所有以前的聊天記錄被刪除。如何保存我之前的聊天記錄,請幫助我。 感謝如何保存在Windows Phone 8聊天

我用下面的代碼

<ListBox Name="listChat" Grid.Row="0" ItemsSource="{Binding Path=Instance.Messages,Source={StaticResource Binder}}"> 
         <ListBox.ItemTemplate> 
          <DataTemplate> 
           <Grid Width="430"> 
            <cc:ChatBubble Width="380" HorizontalAlignment="{Binding Converter={StaticResource MType},ConverterParameter=align}" Opacity="{Binding Converter={StaticResource MType}}" ChatBubbleDirection="{Binding Converter={StaticResource MType},ConverterParameter=direction}" Margin="0,0,0,10" > 
             <Grid> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="Auto"></RowDefinition> 
               <RowDefinition Height="Auto"></RowDefinition> 
               <RowDefinition Height="40"></RowDefinition> 
              </Grid.RowDefinitions> 

              <TextBlock Grid.Row="0" HorizontalAlignment="Left" FontSize="17" Text="{Binding Name}"></TextBlock> 
              <TextBlock Grid.Row="0" HorizontalAlignment="Right" FontSize="17" Text="{Binding SendingDate}"></TextBlock> 

              <TextBlock Grid.Row="1" Name="txt_Msg" Text="{Binding Text}" TextWrapping="Wrap" Width="430"></TextBlock> 


             </Grid> 
            </cc:ChatBubble> 
           </Grid> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 
+0

從您的項目有絕對無關,與你的問題不是生產傾銷隨機碼加載它。 – Will

回答

1

最簡單的方法是獨立存儲

比如我有這樣的輔助類

public static class SettingsManager 
{ 
    private static IsolatedStorageSettings appSettings; 

    public static IsolatedStorageSettings AppSettings 
    { 
     get { return SettingsManager.appSettings; } 
     set { SettingsManager.appSettings = value; } 
    } 

    public static void LoadSettings() 
    { 
     if (appSettings == null) 
      appSettings = IsolatedStorageSettings.ApplicationSettings; 

     if (!appSettings.Contains(SettingValues.LoadedData)) 
      appSettings[SettingValues.LoadedData] = false; 

     appSettings.Save(); 
    } 

    public static void SaveValue(string key, object value) 
    { 
     appSettings[key] = value; 
     appSettings.Save(); 
    } 
} 

然後你可以使用它,如下所示

SettingsManager.SaveValue("myname", someVariableYouWantToStore); 

,並開始後,你可以用

SettingsManager.AppSettings["myname"] 
+0

你好libik你能不能請給我任何例子.. – user

+0

這是這個例子本身,它的作品... – libik

相關問題