예제 #1
0
        private void InitBinding(string id)
        {
            gnpcList = new List <npcs1>();
            try
            {
                using (var reader = new StreamReader("npcList.xml"))
                {
                    XmlSerializer deserializer = new XmlSerializer(typeof(List <npcs1>),
                                                                   new XmlRootAttribute("ArrayOfNpcs1"));
                    gnpcList = (List <npcs1>)deserializer.Deserialize(reader);
                }
            }
            catch
            {
                MessageBox.Show("No image to load.", "Warning", MessageBoxButton.OK);
            }
            npcs1 gfnpc = gnpcList.Find(oElement => oElement.npcId == Convert.ToInt32(NumerId));

            npcId.Text   = Convert.ToString(gfnpc.npcId);
            Name.Text    = gfnpc.npcName;
            Believs.Text = gfnpc.believs;
            Level.Text   = Convert.ToString(gfnpc.npcLevel);
            NpcRole.Text = gfnpc.townRole;
            NumerId      = id;
        }
예제 #2
0
        private void Save(object sender, RoutedEventArgs e)
        {
            npcs1 gfnpc = gnpcList.Find(oElement => oElement.npcId == Convert.ToInt32(NumerId));

            gfnpc.townRole = NpcRole.Text;
            gfnpc.npcName  = Name.Text;
            gfnpc.believs  = Believs.Text;
            gfnpc.npcLevel = Convert.ToInt16(Level.Text);
            gfnpc.image    = where;

            MessageBox.Show("New data has been stored");

            var serializer = new XmlSerializer(gnpcList.GetType());

            using (var writer = XmlWriter.Create("npcList.xml"))
            {
                serializer.Serialize(writer, gnpcList);
            }
        }