How I serialize the data into xml , XBMC is my custom class.
private static XBMC LoadXbmcShows(string XMlFile)
{
XBMC XBMCSShowsList;
TextReader Reader = new StreamReader(XMlFile);
XmlSerializer serializer = new XmlSerializer(typeof(XBMC));
XBMCSShowsList = (XBMC)serializer.Deserialize(Reader);
Reader.Close();
return XBMCSShowsList;
}
XBMC XBMCSList = LoadXbmcShows(_XMLFile);
This is how I create the ObservableCollection
:
readonly ObservableCollection<XBMC> myCollection
= new ObservableCollection<XBMC>()
public ObservableCollection<XBMC> MyCollection
{ get { return myCollection; } }
I am just not sure how to add all the data from XBMCSList
to the collection.
I am also happy to try do it a different way if any one has any ideas.
Code Behind for main window:
namespace MySQlXML
{
public partial class MainWindow : Window
{
static string _XMLFile = @"C:\Dump\test.xml";
List<string> ToCopylist = new List<string>();
readonly ObservableCollection<XBMC> myCollection
= new ObservableCollection<XBMC>();
public ObservableCollection<XBMC> MyCollection
{
get { return myCollection; }
}
public ObservableCollection<XBMC> MyCollection
{
get { return myCollection; }
}
XBMC XBMCSList = LoadXbmcShows(_XMLFile);
MyCollection.Add(XBMCSList);
public MainWindow()
{
InitializeComponent();
Showlistbox.ItemsSource = XBMCSList.Show;
//foreach (XBMCShow show in XBMCSList.Show)
//{
// Showlistbox.Items.Add(show.ShowName);
//}
}
private static XBMC LoadXbmcShows(string XMlFile)
{
XBMC XBMCSShowsList;
TextReader Reader = new StreamReader(XMlFile);
XmlSerializer serializer = new XmlSerializer(typeof(XBMC));
XBMCSShowsList = (XBMC)serializer.Deserialize(Reader);
Reader.Close();
return XBMCSShowsList;
}
}
}