public MainWindow()
 {
     InitializeComponent();
     DataContext = new ViewModels.MainWindowViewModel();
 }
        private void OnMainFileSaveAsMenuClicked(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();

            dialog.Filter = FilterTxt + "|" +
                            FilterJson + "|" +
                            FilterXml + "|" +
                            FilterSoap + "|" +
                            FilterBinary;

            dialog.FilterIndex = 1;

            bool?dialogResult = dialog.ShowDialog();

            if (dialogResult == true)
            {
                string filePath = dialog.FileName;
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }

                string content = "";

                List <TodoTask> items = new List <TodoTask>();
                ViewModels.MainWindowViewModel viewModel = (this.DataContext as ViewModels.MainWindowViewModel);
                foreach (var todoTaskViewModel in viewModel.TodoTaskItems)
                {
                    Models.TodoTask item = new Models.TodoTask();

                    item.Description = todoTaskViewModel.Description;
                    // todo: all properties
                    item.DueBy       = todoTaskViewModel.DueBy;
                    item.IsCompleted = todoTaskViewModel.IsCompleted;
                    item.CompletedOn = todoTaskViewModel.CompletedOn;
                    items.Add(item);
                }

                if (dialog.FilterIndex == 1)
                {
                    System.IO.StringWriter writer = new System.IO.StringWriter();

                    content = writer.ToString();

                    writer.Dispose();
                }
                else if (dialog.FilterIndex == 2)
                {
                    string json = Newtonsoft
                                  .Json
                                  .JsonConvert
                                  .SerializeObject(items);
                    content = json;
                }
                else if (dialog.FilterIndex == 3)
                {
                    System.Xml.Serialization.XmlSerializer serializer =
                        new System.Xml.Serialization.XmlSerializer(typeof(List <TodoTask>));
                    System.IO.MemoryStream stream = new System.IO.MemoryStream();
                    serializer.Serialize(stream, items);
                    stream.Seek(0, System.IO.SeekOrigin.Begin);

                    System.IO.StreamReader reader = new System.IO.StreamReader(stream);
                    content = reader.ReadToEnd();

                    reader.Dispose();
                    stream.Dispose();
                }
                else if (dialog.FilterIndex == 4)
                {
                    //System.Runtime.Serialization.Formatters.Soap.SoapFormatter serializer =
                    //    new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
                    //System.IO.MemoryStream stream = new System.IO.MemoryStream();
                    //serializer.Serialize(stream, document);
                    //stream.Seek(0, System.IO.SeekOrigin.Begin);

                    //System.IO.StreamReader reader = new System.IO.StreamReader(stream);
                    //content = reader.ReadToEnd();

                    //reader.Dispose();
                    //stream.Dispose();
                }
                else
                {
                    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer =
                        new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    System.IO.MemoryStream stream = new System.IO.MemoryStream();
                    serializer.Serialize(stream, items);

                    stream.Seek(0, System.IO.SeekOrigin.Begin);
                    content = Convert.ToBase64String(stream.ToArray());

                    stream.Dispose();
                }

                System.IO.File.WriteAllText(filePath, content);
            }
        }