/// <summary> /// Updates the Targets of every field. This is done when changes get discarded. So the values get overridden with the values in the source of the binding /// </summary> private void UpdateTargets() { BindingExpression be = TitleTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateTarget(); } be = AuthorTextbox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateTarget(); } be = DescriptionTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateTarget(); } be = CreateDatePicker.GetBindingExpression(DatePicker.SelectedDateProperty); if (be != null) { be.UpdateTarget(); } be = RatingTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateTarget(); } }
/// <summary> /// Checks if the scenario details need saving or not /// </summary> /// <returns></returns> public bool NeedSave() { BindingExpression be = TitleTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null && be.IsDirty) { return(true); } be = AuthorTextbox.GetBindingExpression(TextBox.TextProperty); if (be != null && be.IsDirty) { return(true); } be = DescriptionTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null && be.IsDirty) { return(true); } be = CreateDatePicker.GetBindingExpression(DatePicker.SelectedDateProperty); if (be != null && be.IsDirty) { return(true); } be = RatingTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null && be.IsDirty) { return(true); } return(false); }
/// <summary> /// Updates the changes in the scenario values into the datamodel. Occurs when the save button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveDataButton_OnClickDataButton_Click(object sender, RoutedEventArgs e) { BindingExpression be = TitleTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateSource(); } be = AuthorTextbox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateSource(); } be = DescriptionTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateSource(); } be = CreateDatePicker.GetBindingExpression(DatePicker.SelectedDateProperty); if (be != null) { be.UpdateSource(); } be = RatingTextBox.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.UpdateSource(); } WorkbookModel workbook = new WorkbookModel(Globals.ThisAddIn.Application.ActiveWorkbook); workbook.ShouldScanAfterSave = false; Globals.ThisAddIn.Application.ActiveWorkbook.Save(); workbook.ShouldScanAfterSave = true; }