/// <summary> /// Constructs a new instance of DataFormContentLoadEventArgs. /// </summary> /// <param name="content">The content that was loaded or will be loaded.</param> /// <param name="mode">The mode of the DataForm.</param> public DataFormContentLoadEventArgs(FrameworkElement content, DataFormMode mode) { this.Content = content; this.Mode = mode; }
/// <summary> /// Re-generates the UI if a template or direct content change requires it. /// </summary> /// <param name="changedTemplateMode">The mode for which template was changed, or null if the content was changed.</param> /// <param name="oldContent">The old Content value, or null in the case of a template change.</param> private void RegenerateUI(DataFormMode? changedTemplateMode, object oldContent) { if (this.CurrentItemType != null && (this._currentlyUsedTemplate.Count == 0 || (this._currentlyUsedTemplate.ContainsKey(this.CurrentItemType) && this.ShouldRegenerateUI(changedTemplateMode)))) { if (changedTemplateMode == null && this._contentPresenter.Content == oldContent && oldContent != null) { this.RemoveContent(oldContent as FrameworkElement); } else if (this.Mode == DataFormMode.ReadOnly) { this.RemoveContentForType(this.CurrentItemType, this._readOnlyContentsNew); this.RemoveContentForType(this.CurrentItemType, this._readOnlyContentsOld); } else if (this.Mode == DataFormMode.Edit) { this.RemoveContentForType(this.CurrentItemType, this._editContentsNew); this.RemoveContentForType(this.CurrentItemType, this._editContentsOld); } else { this.RemoveContentForType(this.CurrentItemType, this._addNewContentsNew); this.RemoveContentForType(this.CurrentItemType, this._addNewContentsOld); } this.GenerateUI(false /* clearEntityErrors */); } SetAllCanPropertiesAndUpdate(this, true /* onlyUpdateStates */); }
/// <summary> /// Returns a value indicating whether or not the UI should be re-generated based on /// a changed template. /// </summary> /// <param name="changedTemplateMode">The mode for which template was changed, or null if the content was changed.</param> /// <returns>A value indicating whether or not the UI should be re-generated.</returns> private bool ShouldRegenerateUI(DataFormMode? changedTemplateMode) { Debug.Assert(this.CurrentItemType != null, "ShouldUpdateTemplate should never be called if the current item type is null."); // If the changed template was for the same mode as the current mode, // we know we should update the template. if (this.Mode == changedTemplateMode) { return true; } DataFormMode? currentlyUsedTemplateMode = this._currentlyUsedTemplate[this.CurrentItemType]; if (currentlyUsedTemplateMode == null) { // We're currently using direct content, so we will re-generate the UI no matter what // template has changed (since every template takes precedence over the direct content). return true; } if (changedTemplateMode == null) { // We're using a template and the direct content has changed, so there's no need to update. return false; } // If the changed template was not for the same mode as the current mode, // then we should update the template if the mode for the currently used template // is after the mode for the changed template in the fallback list. if (this.Mode == DataFormMode.ReadOnly) { // If we're in read-only mode, the fallback mechanism is edit -> add-new. return (currentlyUsedTemplateMode == DataFormMode.Edit && changedTemplateMode == DataFormMode.Edit) || currentlyUsedTemplateMode == DataFormMode.AddNew; } else if (this.Mode == DataFormMode.Edit) { // If we're in edit mode, the fallback mechanism is add-new -> read-only. return (currentlyUsedTemplateMode == DataFormMode.AddNew && changedTemplateMode == DataFormMode.AddNew) || currentlyUsedTemplateMode == DataFormMode.ReadOnly; } else if (this.Mode == DataFormMode.AddNew) { // If we're in add-new mode, the fallback mechanism is edit -> read-only. return (currentlyUsedTemplateMode == DataFormMode.Edit && changedTemplateMode == DataFormMode.Edit) || currentlyUsedTemplateMode == DataFormMode.ReadOnly; } return false; }
/// <summary> /// 'Add' button is hit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void itemDataForm_AddingNewItem(object sender, DataFormAddingNewItemEventArgs e) { editMode = DataFormMode.AddNew; }
/// <summary> /// "Edit" button is hit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void itemDataForm_BeginningEdit(object sender, System.ComponentModel.CancelEventArgs e) { editMode = DataFormMode.Edit; }
// Executes when the user navigates to this page. protected override void OnNavigatedTo(NavigationEventArgs e) { this.editMode = DataFormMode.ReadOnly; this.ContentPageCtx = ModelProvider.Instance.GetContentPageContext(e.Uri.ToString()); this.BeginUpdateEntireUI(); }
/// <summary> /// Thread body /// </summary> /// <param name="state"></param> private void StartWork(object state) { MediaView mediaView = state as MediaView; media savedMedia = null; media theMedia = new media(); mediaView.Merge(theMedia, editMode); // Save to backend if (this.editMode == DataFormMode.Edit) { // Edit mode AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); EventHandler <save_MediaCompletedEventArgs> h1 = (s, e) => { // TODO: handle error from server side savedMedia = e.Result; nextOneAutoResetEvent.Set(); }; Globals.WSClient.save_MediaCompleted += h1; Globals.WSClient.save_MediaAsync(theMedia); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.save_MediaCompleted -= h1; } else { // // Add new mode // // Get file content byte[] content = ShopproHelper.ReadFully(fileInfo.OpenRead()); // Save to the backend AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); EventHandler <createNew_MediaCompletedEventArgs> h3 = (s, e) => { // TODO: handle error from server side savedMedia = e.Result; nextOneAutoResetEvent.Set(); }; Globals.WSClient.createNew_MediaCompleted += h3; Globals.WSClient.createNew_MediaAsync(theMedia, content); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.createNew_MediaCompleted -= h3; } // Check return result. If failure, savedCategory will be null if (savedMedia != null) { this.Dispatcher.BeginInvoke(delegate() { mediaView.Restore(new MediaView(savedMedia)); }); } else { // Show error message ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry.", false); // Back to readonly mode this.Dispatcher.BeginInvoke(delegate() { // Restore cached UI data mediaView.CancelEdit(); this.mediaDataForm.CancelEdit(); }); } // No unsaved item this.editMode = DataFormMode.ReadOnly; this.fileInfo = null; // Hide busy indicator ShopproHelper.HideBusyIndicator(this); // Go to original page if necessary if (this.ContentPageCtx.GotoAddNewPage) { ShopproHelper.GoToContentPage(this, PageEnum.MediaListPage); } }