1
我正在構建一個包含多個比賽的應用程序,並且每個比賽都有多個集合。使用隔離存儲在WP7中保存集合
只有我寫錦標賽名稱時,如果我嘗試向它的集合添加任何內容,它纔會崩潰,IsolatedStorage才能正常工作。
我的比賽類
public class TournamentMain
{
public int ID = 0;
public string name { get; set; }
public double buy_in { get; set; }
public double re_buy { get; set; }
public double add_on { get; set; }
public int blindindex = 1;
public int placeindex = 1;
public int playerindex = 1;
public ObservableCollection<Blind> blinds { get; set; }
public ObservableCollection<Player> players { get; set; }
public ObservableCollection<Place> places { get; set; }
public ObservableCollection<Paidplace> paidplaces {get; set;}
public TournamentMain() {
players = new ObservableCollection<Player>();
places = new ObservableCollection<Place>();
blinds = new ObservableCollection<Blind>();
paidplaces = new ObservableCollection<Paidplace>();
} }
我的存儲類
public class StorageSaveing
{
static XmlSerializer serializer;
public static void saveIT()
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream("data.txt",
FileMode.Create,
FileAccess.Write,
store))
{
serializer = new XmlSerializer(typeof(ObservableCollection<TournamentMain>));
serializer.Serialize(stream, App.tournaments);
}
}
public static ObservableCollection<TournamentMain> loadIT()
{
using( var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream("data.txt",
FileMode.OpenOrCreate,
FileAccess.Read,
store))
using( var reader = new StreamReader(stream))
{
serializer = new XmlSerializer(typeof(ObservableCollection<TournamentMain>));
return reader.EndOfStream
? new ObservableCollection<TournamentMain>()
: (ObservableCollection<TournamentMain>)serializer.Deserialize(reader);
}
}
}
它叫出來的時候應用程序關閉和打開
任何幫助,非常感謝!! :)
這裏是TournamentMain類
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace PokerAssistant
{
public class TournamentMain
{
public int ID = 0;
public string name { get; set; }
public double buy_in { get; set; }
public double re_buy { get; set; }
public double add_on { get; set; }
public int blindindex = 1;
public int placeindex = 1;
public int playerindex = 1;
private ObservableCollection<Blind> _blinds;
public ObservableCollection<Blind> blinds { get{
return _blinds;
}
set {
_blinds = value;
}
}
public ObservableCollection<Player> players { get; set; }
public ObservableCollection<Place> places { get; set; }
public ObservableCollection<Paidplace> paidplaces {get; set;}
public TournamentMain() {
players = new ObservableCollection<Player>();
places = new ObservableCollection<Place>();
_blinds = new ObservableCollection<Blind>();
paidplaces = new ObservableCollection<Paidplace>();
}
public double calculatePot() {
double totalsum = 0;
foreach (Player player in players)
{
totalsum += player.cash;
}
foreach (Blind blind in blinds)
{
totalsum += blind.Ante * players.Count;
}
return totalsum;
}
public void setPlacesList() {
int i=1;
foreach(Double place in calculatePlaces()){
Paidplace p = new Paidplace();
p.name = i + ". " + place + "$";
paidplaces.Add(p);
i++;
}
}
public List<double> calculatePlaces() {
List<double> paidplaces = new List<double>();
double total = 0;
foreach (Place place in places)
{
paidplaces.Add(calculatePot() * (place.place_pr/100));
total += calculatePot() * (place.place_pr/100);
}
total = calculatePot()-total;
paidplaces.Add(total);
return paidplaces;
}
public int playersCount() {
return players.Count;
}
}
}
增加了一個像這樣的集合,但仍然崩潰:S 'private ObservableCollection _blinds; public ObservableCollection blinds {get { return _blinds; } set { _blinds = value; } }' –
Mikk
2012-02-16 12:56:01
你可以發佈整個TournamentMain類 – MyKuLLSKI 2012-02-16 14:32:01
發佈的代碼在 – Mikk 2012-02-22 13:45:17