Esempio n. 1
0
 public MainWindow()
 {
     InitializeComponent();
     agents.Add(new Agent()
     {
         ID = "001", CodeName = "Nina", Speciality = "Assassination", Assignment = "UpperVolta"
     });
     agents.Add(new Agent("007", "James Bond", "Martinis", "North Korea"));
     agentGrid.DataContext = agents;
 }
Esempio n. 2
0
        private void OpenFileCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            filename = tbxFileName.Text;
            Agents tempAgents = new Agents();

            // Create an instance of the XmlSerializer class and specify the type of object to serialize.
            XmlSerializer serializer = new XmlSerializer(typeof(Agents));

            try
            {
                TextReader reader = new StreamReader(filename);
                // Deserialize all the agents.
                tempAgents = (Agents)serializer.Deserialize(reader);
                reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unable to open file", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            // We have to insert the agents in the existing collection. If we just assign tempAgents to agents then the bindings to agents will brake!
            agents.Clear();
            foreach (var agent in tempAgents)
            {
                agents.Add(agent);
            }
        }
Esempio n. 3
0
        void btnAddNew_Click(object sender, RoutedEventArgs e)
        {
            Agents agents = (Agents)this.FindResource("agents");

            agents.Add(new Agent());
            lbxAgents.SelectedIndex = lbxAgents.Items.Count - 1;
            tbxId.Focus();
        }
Esempio n. 4
0
        private void AddClick(object sender, RoutedEventArgs e)
        {
            AddWindow addWindow = new AddWindow();

            if (addWindow.ShowDialog() != null && addWindow.newAgent != null)
            {
                Agent newAgent = addWindow.newAgent;
                aListe.Add(newAgent);
            }
        }