Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / C#

Displaying a Dialog Box in SCSF

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
28 Aug 2008CPOL2 min read 37.6K   444   16  
This article explains how to display a dialog box in SCSF.
//----------------------------------------------------------------------------------------
// patterns & practices - Smart Client Software Factory - Guidance Package
//
// This file was generated by this guidance package as part of the solution template
//
// This class contains code that otherwise would be repeated in every presenter when using the M-V-P pattern. 
// It includes a reference to a generic view and a reference to the WorkItem it belongs. 
// It also provides virtual methods to work with the controlled view
// 
// For more information see: 
// ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ms.practices.scsf.2007may/SCSF/html/03-01-010-How_to_Create_Smart_Client_Solutions.htm
//
// Latest version of this Guidance Package: http://go.microsoft.com/fwlink/?LinkId=62182
//----------------------------------------------------------------------------------------

using Microsoft.Practices.CompositeUI;
using System;
using Microsoft.Practices.CompositeUI.SmartParts;

namespace DialogBox.Infrastructure.Interface
{
    public abstract class Presenter<TView> : IDisposable
    {
        private TView _view;
        private WorkItem _workItem;

        public TView View
        {
            get { return _view; }
            set { _view = value; OnViewSet(); }
        }

        [ServiceDependency]
        public WorkItem WorkItem
        {
            get { return _workItem; }
            set { _workItem = value; }
        }

        protected virtual void CloseView()
        {
            Services.IWorkspaceLocatorService locator = WorkItem.Services.Get<Services.IWorkspaceLocatorService>();
            IWorkspace wks = locator.FindContainingWorkspace(WorkItem, View);
            if (wks != null)
                wks.Close(View);
        }

        public virtual void OnViewReady() { }
        protected virtual void OnViewSet() { }

        ~Presenter()
        {
            Dispose(false);
        }

        /// <summary>
        /// See <see cref="System.IDisposable.Dispose"/> for more information.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Called when the object is being disposed or finalized.
        /// </summary>
        /// <param name="disposing">True when the object is being disposed (and therefore can
        /// access managed members); false when the object is being finalized without first
        /// having been disposed (and therefore can only touch unmanaged members).</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_workItem != null)
                    _workItem.Items.Remove(this);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) CreatorsNepal IT Solutions Pvt. Ltd.
Nepal Nepal
If you have any questions, you can also write me at:
anil_157@hotmail.com

Comments and Discussions