コード例 #1
0
ファイル: Workspace.cs プロジェクト: bravesoftdz/sofia-svn
        /// <summary>
        /// Activates the smartPart on the workspace.
        /// </summary>
        /// <param name="smartPart">The smart part to activate.</param>
        /// <exception cref="ArgumentException">The smartPart
        /// was not previously shown in the workspace.</exception>
        /// <exception cref="ArgumentException">The smartPart cannot be
        /// assigned to TSmartPart.</exception>
        /// <remarks>
        /// <see cref="OnActivate"/> and <see cref="SmartPartActivated"/>
        /// wil only be called if the smartPart is different than the
        /// <see cref="ActiveSmartPart"/>.
        /// </remarks>
        public bool Activate(object smartPart)
        {
            Guard.ArgumentNotNull(smartPart, "smartPart");
            ThrowIfUnsupportedSP(smartPart);
            ThrowIfSmartPartNotShownPreviously((TSmartPart)smartPart);

            if (activeSmartPart != smartPart)
            {
                if (!_suppressSmartPartActivating)
                {
                    WorkspaceCancelEventArgs e = RaiseSmartPartActivating(smartPart);

                    if (e.Cancel)
                    {
                        return(false);
                    }
                }

                OnActivate((TSmartPart)smartPart);
                activeSmartPart = smartPart;
                RaiseSmartPartActivated(smartPart);
            }

            return(true);
        }
コード例 #2
0
 /// <summary>
 /// Raises the <see cref="SmartPartClosing"/> event using the specified
 /// event argument.
 /// </summary>
 /// <param name="e">The arguments to pass to the event.</param>
 protected void RaiseSmartPartClosing(WorkspaceCancelEventArgs e)
 {
     if (this.SmartPartClosing != null)
     {
         this.SmartPartClosing(this, e);
     }
 }
コード例 #3
0
        /// <summary>
        /// Raises the <see cref="SmartPartClosing"/> event.
        /// </summary>
        /// <param name="smartPart">The smart part that is being closed.</param>
        protected WorkspaceCancelEventArgs RaiseSmartPartClosing(object smartPart)
        {
            WorkspaceCancelEventArgs cancelArgs = new WorkspaceCancelEventArgs(smartPart);

            RaiseSmartPartClosing(cancelArgs);

            return(cancelArgs);
        }
コード例 #4
0
        /// <summary>
        /// Closes the smart part and resets (sets to null) the <see cref="ActiveSmartPart"/>.
        /// </summary>
        /// <exception cref="ArgumentException">The smartPart
        /// was not previously shown in the workspace.</exception>
        /// <exception cref="ArgumentException">The smartPart cannot be
        /// assigned to TSmartPart.</exception>
        public void Close(object smartPart)
        {
            Guard.ArgumentNotNull(smartPart, "smartPart");
            ThrowIfUnsupportedSP(smartPart);
            ThrowIfSmartPartNotShownPreviously((TSmartPart)smartPart);

            WorkspaceCancelEventArgs cancelArgs = RaiseSmartPartClosing(smartPart);

            if (cancelArgs.Cancel == false)
            {
                CloseInternal((TSmartPart)smartPart);
            }
        }
コード例 #5
0
ファイル: Workspace.cs プロジェクト: bravesoftdz/sofia-svn
        /// <summary>
        /// Shows SmartPart using the given <see cref="ISmartPartInfo"/>.
        /// </summary>
        /// <exception cref="ArgumentException">The smartPart cannot be
        /// assigned to TSmartPart.</exception>
        /// <remarks>
        /// If the smartPart was previously shown,
        /// <see cref="ApplySmartPartInfo"/> and <see cref="Activate"/> will be called.
        /// Otherwise, <see cref="OnShow"/> is called.
        /// </remarks>
        public bool Show(object smartPart, ISmartPartInfo smartPartInfo)
        {
            Guard.ArgumentNotNull(smartPart, "smartPart");
            Guard.ArgumentNotNull(smartPartInfo, "smartPartInfo");
            ThrowIfUnsupportedSP(smartPart);

            TSmartPartInfo typedInfo      = GetSupportedSPI(smartPartInfo);
            TSmartPart     typedSmartPart = (TSmartPart)smartPart;

            if (smartParts.Contains(typedSmartPart))
            {
                ApplySmartPartInfo(smartPart, smartPartInfo);
                return(Activate(smartPart));
            }
            else
            {
                WorkspaceCancelEventArgs e = RaiseSmartPartActivating(smartPart);

                if (e.Cancel)
                {
                    return(false);
                }

                smartParts.Add(typedSmartPart);
                _suppressSmartPartActivating = true;

                try
                {
                    OnShow(typedSmartPart, typedInfo);
                }
                finally
                {
                    _suppressSmartPartActivating = false;
                }

                return(true);
            }
        }
コード例 #6
0
 /// <summary>
 /// 数据列表关闭事件
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="Microsoft.Practices.CompositeUI.SmartParts.WorkspaceCancelEventArgs"/> instance containing the event data.</param>
 private void DataList_SmartPartClosing(object sender, WorkspaceCancelEventArgs e)
 {
     AuthorizationAttribute[] attrs = (AuthorizationAttribute[])e.SmartPart.GetType().GetCustomAttributes(typeof(AuthorizationAttribute), true);
     if (attrs.Length > 0) {
         try {
             StoreLayout((Control)e.SmartPart, attrs[0]);
         }
         catch { }
     }
 }
コード例 #7
0
 void OnSmartPartClosingEvent(object sender, WorkspaceCancelEventArgs e)
 {
     composedWorkspace.RaiseSmartPartClosing(e);
 }
コード例 #8
0
 void WorkspaceComposer_SmartPartActivating(object sender, WorkspaceCancelEventArgs e)
 {
     composedWorkspace.RaiseSmartPartActivating(e);
 }
コード例 #9
0
        private void contentWorkspace_SmartPartActivating(object sender, WorkspaceCancelEventArgs e)
        {
            //uncomment this code to see how you can use the SmartPartActivating event to optionally cancel smart part activations
            //NOTE: IWorkspace.SmartPartActivating is not a standard part of CAB, so note that you will be tying yourself to this implementation
            //of CAB. I had to add this event myself for my own benefit

            //if (MessageBox.Show("Navigate to '" + e.SmartPart + "'?", "Confirm Navigation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            //{
            //    e.Cancel = true;
            //}
        }