Click here to Skip to main content
11,491,742 members (66,196 online)
Click here to Skip to main content
Add your own
alternative version

Open Child Window in MVVM environment

, 14 May 2012 CPOL 26.3K 1.1K 12
How to open pop up window in MVVM environment. You can use it in WPF or Silverlight.
WindowWithMVVM.zip
WindowWithMVVM
WindowWithMVVM.suo
WindowWithMVVM.Web
App_Data
bin
WindowWithMVVM.Web.dll
WindowWithMVVM.Web.pdb
ClientBin
WindowWithMVVM.xap
Models
Shared
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
GenerateResource.read.1.tlog
GenerateResource.write.1.tlog
ResolveAssemblyReference.cache
TempPE
WindowWithMVVM.Web.dll
WindowWithMVVM.Web.pdb
WindowWithMVVM.Web.Resources.RegistrationDataResources.resources
WindowWithMVVM.Web.Resources.ValidationErrorResources.resources
Properties
Resources
Services
WindowWithMVVM.Web.csproj.user
WindowWithMVVM
Assets
Resources
Bin
Debug
ar
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
bg
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
ca
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
cs
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
da
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
de
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
el
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
es
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
et
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
eu
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
fi
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
fr
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
he
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
hr
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
hu
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
id
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
it
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
ja
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
ko
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
lt
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
lv
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
ms
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
nl
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
no
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
pl
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
pt
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
pt-BR
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
ro
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
ru
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
sk
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
sl
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
sr-Cyrl-CS
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
sr-Latn-CS
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
sv
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
System.ComponentModel.DataAnnotations.dll
System.ServiceModel.DomainServices.Client.dll
System.ServiceModel.DomainServices.Client.Web.dll
System.ServiceModel.Web.Extensions.dll
System.Windows.Controls.Data.DataForm.Toolkit.dll
System.Windows.Controls.Data.Input.dll
System.Windows.Controls.dll
System.Windows.Controls.Navigation.dll
th
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
tr
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
uk
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
vi
System.ComponentModel.DataAnnotations.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.resources.dll
WindowWithMVVM.dll
WindowWithMVVM.pdb
WindowWithMVVM.xap
zh-Hans
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
zh-Hant
System.ComponentModel.DataAnnotations.resources.dll
System.ServiceModel.DomainServices.Client.resources.dll
System.ServiceModel.DomainServices.Client.Web.resources.dll
System.ServiceModel.Web.Extensions.resources.dll
System.Windows.Controls.Data.Input.resources.dll
System.Windows.Controls.Navigation.resources.dll
System.Windows.Controls.resources.dll
Controls
Generated_Code
Models
Shared
Helpers
Libs
System.Windows.Controls.Data.DataForm.Toolkit.dll
Models
obj
Debug
Assets
Controls
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
GenerateResource.read.1.tlog
GenerateResource.write.1.tlog
ResolveAssemblyReference.cache
TempPE
Assets.Resources.ApplicationStrings.Designer.cs.dll
Assets.Resources.ErrorResources.Designer.cs.dll
Assets.Resources.SecurityQuestions.Designer.cs.dll
Web.Resources.RegistrationDataResources.Designer.cs.dll
Web.Resources.ValidationErrorResources.Designer.cs.dll
Views
Login
WindowWithMVVM.Assets.Resources.ApplicationStrings.resources
WindowWithMVVM.Assets.Resources.ErrorResources.resources
WindowWithMVVM.Assets.Resources.SecurityQuestions.resources
WindowWithMVVM.dll
WindowWithMVVM.g.resources
WindowWithMVVM.pdb
WindowWithMVVM.Web.Resources.RegistrationDataResources.resources
WindowWithMVVM.Web.Resources.ValidationErrorResources.resources
Properties
ViewModel
Views
Login
Web
Resources
WindowWithMVVM.csproj.user
namespace WindowWithMVVM
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using WindowWithMVVM.Views;
    using System.Windows;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class Home : Page
    {
        /// <summary>
        /// Creates a new <see cref="Home"/> instance.
        /// </summary>
        public Home()
        {
            InitializeComponent();

            this.Title = ApplicationStrings.HomePageTitle;
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var window = new ChildWindow1 { DataContext = this.DataContext };
            window.Unloaded -= new System.Windows.RoutedEventHandler(ChildWindow_Unloaded);
            window.Unloaded += new System.Windows.RoutedEventHandler(ChildWindow_Unloaded);
            window.Show();
        }

        void ChildWindow_Unloaded(object sender, System.Windows.RoutedEventArgs e)
        {
            //You can do child window closing coding here like collect object, saving samething or changing status
            MessageBox.Show("Child window is closed now.");
        }
    }
}

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)

Share

About the Author

ManojKumar19
Architect
United States United States
Manoj Kumar

Architect, Lead Software Engineer and Senior BI Developer | Microsoft Certified Technology Specialist(MCTS) | Exp in C#, ASP.Net, MVC, Razor View Engine and EF Code First, HTML5, CSS3, JQuery, Javascript, AngularJS, JSON, AJAX, KnockoutJS, Silverlight, WPF, WCF, WF, SSRS, SSAS, SSIS, ETL, SQL Server, Usability/User Experience etc.

He lives with his wife Supriya and daughter Tisya in Bay Area.
Follow on   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 14 May 2012
Article Copyright 2012 by ManojKumar19
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid