PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/PrismLibrary/Silverlight/Prism.Interactivity/InteractionRequest/PopupChildWindowAction.cs

#
C# | 88 lines | 42 code | 7 blank | 39 comment | 0 complexity | 3005122b9897cb50ae0316b64697ec5c MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System.Windows;
18using System.Windows.Controls;
19
20namespace Microsoft.Practices.Prism.Interactivity.InteractionRequest
21{
22    /// <summary>
23    /// Concrete class that pops up a specified child window or a default child window configured with a data template.
24    /// </summary>
25    public class PopupChildWindowAction : PopupChildWindowActionBase
26    {
27        /// <summary>
28        /// The child window to display as part of the popup.
29        /// </summary>
30        public static readonly DependencyProperty ChildWindowProperty =
31            DependencyProperty.Register(
32                "ChildWindow",
33                typeof(ChildWindow),
34                typeof(PopupChildWindowAction),
35                new PropertyMetadata(null));
36
37        /// <summary>
38        /// The <see cref="DataTemplate"/> to apply to the popup content.
39        /// </summary>
40        public static readonly DependencyProperty ContentTemplateProperty =
41            DependencyProperty.Register(
42                "ContentTemplate",
43                typeof(DataTemplate),
44                typeof(PopupChildWindowAction),
45                new PropertyMetadata(null));
46
47        /// <summary>
48        /// Gets or sets the child window to pop up.
49        /// </summary>
50        /// <remarks>
51        /// If not specified, a default child window is used instead.
52        /// </remarks>
53        public ChildWindow ChildWindow
54        {
55            get { return (ChildWindow)GetValue(ChildWindowProperty); }
56            set { SetValue(ChildWindowProperty, value); }
57        }
58
59        /// <summary>
60        /// Gets or sets the content template for a default child window.
61        /// </summary>
62        public DataTemplate ContentTemplate
63        {
64            get { return (DataTemplate)GetValue(ContentTemplateProperty); }
65            set { SetValue(ContentTemplateProperty, value); }
66        }
67
68        /// <summary>
69        /// Returns the child window to display as part of the trigger action.
70        /// </summary>
71        /// <param name="notification">The notification to display in the child window.</param>
72        /// <returns></returns>
73        protected override ChildWindow GetChildWindow(Notification notification)
74        {
75            var childWindow = this.ChildWindow ?? this.CreateDefaultWindow(notification);
76            childWindow.DataContext = notification;
77
78            return childWindow;
79        }
80
81        private ChildWindow CreateDefaultWindow(Notification notification)
82        {
83            return notification is Confirmation
84                ? (ChildWindow)new ConfirmationChildWindow { ConfirmationTemplate = this.ContentTemplate }
85                : new NotificationChildWindow { NotificationTemplate = this.ContentTemplate };
86        }
87    }
88}