Example #1
0
 // Called during a remove operation
 private void detach_Field(ToDoField toDo)
 {
     NotifyPropertyChanging("ToDoField");
     toDo.Item = null;
 }
Example #2
0
        // When ok is clicked, save the item and add to database
        // Make sure all the fields are also stored
        private void appBarOkButton_Click(object sender, EventArgs e)
        {
            // Confirm there is some text in the text box.
            if (newEntryNameTextBox.Text.Length > 0)
            {
                // Check if this is a new item or existing item
                if (LoadedItemInfo == null)
                {
                    List<ToDoField> NewFields = new List<ToDoField>();
                    // Create a new to-do item.
                    LoadedItem = new ToDoItem
                    {
                        ItemName = newEntryNameTextBox.Text,
                        Category = (ToDoCategory)categoriesListPicker.SelectedItem
                    };

                    ToDoField UsernameField = new ToDoField
                    {
                        FieldName = "username",
                        FieldValue = newUserNameTextBox.Text,
                        Item = LoadedItem
                    };

                    ToDoField PasswordField = new ToDoField
                    {
                        FieldName = "password",
                        FieldValue = newPasswordTextBox.Text,
                        Item = LoadedItem
                    };
                    ToDoField NoteField = new ToDoField
                    {
                        FieldName = "note",
                        FieldValue = newNoteTextBox.Text,
                        Item = LoadedItem
                    };

                    NewFields.Add(UsernameField);
                    NewFields.Add(PasswordField);
                    NewFields.Add(NoteField);

                    // Add the item to the ViewModel.
                    App.ViewModel.AddToDoItem(LoadedItem);
                    App.ViewModel.AddToDoField(NewFields);
                }
                else
                {
                    Dictionary<string, string> fieldValueDict = new Dictionary<string, string>();
                    foreach (KeyValuePair<string, TextBox> updateField in UpdateFieldDictionary)
                    {
                        fieldValueDict.Add(updateField.Key, updateField.Value.Text);
                    }
                    //fieldValueDict.Add("username", newUserNameTextBox.Text);
                    //fieldValueDict.Add("password", newPasswordTextBox.Text);
                    //fieldValueDict.Add("note", newNoteTextBox.Text);
                    App.ViewModel.UpdateItem(fieldValueDict, LoadedItemInfo);
                }

                List<ToDoField> NewFieldsDup = new List<ToDoField>();
                foreach (KeyValuePair<string, TextBox> newFieldInfo in NewFieldDictionary)
                {
                    ToDoField newField = new ToDoField
                    {
                        FieldName = newFieldInfo.Key,
                        FieldValue = newFieldInfo.Value.Text,
                        Item = LoadedItem
                    };
                    NewFieldsDup.Add(newField);

                }
                App.ViewModel.AddToDoField(NewFieldsDup);

                // Return to the main page.
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
            }
        }
Example #3
0
 // Called during an add operation
 private void attach_Field(ToDoField toDo)
 {
     NotifyPropertyChanging("ToDoField");
     toDo.Item = this;
 }
Example #4
0
 // Add a field box to the view
 private void addFieldBox(ToDoField f)
 {
     TextBlock newFieldNameBlock = new TextBlock();
     newFieldNameBlock.Text = f.FieldName;
     ContentPanel.Children.Add(newFieldNameBlock);
     TextBox newFieldValueBox = new TextBox();
     newFieldValueBox.Text = f.FieldValue;
     ContentPanel.Children.Add(newFieldValueBox);
     UpdateFieldDictionary.Add(f.FieldName, newFieldValueBox);
     //Here is a link on bindings
     // http://www.windowsphonegeek.com/articles/Talking-about-Data-Binding-in-WP7--Coding4fun-TextBoxBinding-helper-in-depth
 }