PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms 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. //===================================================================================
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. namespace Microsoft.Practices.Prism.Interactivity.InteractionRequest
  20. {
  21. /// <summary>
  22. /// Concrete class that pops up a specified child window or a default child window configured with a data template.
  23. /// </summary>
  24. public class PopupChildWindowAction : PopupChildWindowActionBase
  25. {
  26. /// <summary>
  27. /// The child window to display as part of the popup.
  28. /// </summary>
  29. public static readonly DependencyProperty ChildWindowProperty =
  30. DependencyProperty.Register(
  31. "ChildWindow",
  32. typeof(ChildWindow),
  33. typeof(PopupChildWindowAction),
  34. new PropertyMetadata(null));
  35. /// <summary>
  36. /// The <see cref="DataTemplate"/> to apply to the popup content.
  37. /// </summary>
  38. public static readonly DependencyProperty ContentTemplateProperty =
  39. DependencyProperty.Register(
  40. "ContentTemplate",
  41. typeof(DataTemplate),
  42. typeof(PopupChildWindowAction),
  43. new PropertyMetadata(null));
  44. /// <summary>
  45. /// Gets or sets the child window to pop up.
  46. /// </summary>
  47. /// <remarks>
  48. /// If not specified, a default child window is used instead.
  49. /// </remarks>
  50. public ChildWindow ChildWindow
  51. {
  52. get { return (ChildWindow)GetValue(ChildWindowProperty); }
  53. set { SetValue(ChildWindowProperty, value); }
  54. }
  55. /// <summary>
  56. /// Gets or sets the content template for a default child window.
  57. /// </summary>
  58. public DataTemplate ContentTemplate
  59. {
  60. get { return (DataTemplate)GetValue(ContentTemplateProperty); }
  61. set { SetValue(ContentTemplateProperty, value); }
  62. }
  63. /// <summary>
  64. /// Returns the child window to display as part of the trigger action.
  65. /// </summary>
  66. /// <param name="notification">The notification to display in the child window.</param>
  67. /// <returns></returns>
  68. protected override ChildWindow GetChildWindow(Notification notification)
  69. {
  70. var childWindow = this.ChildWindow ?? this.CreateDefaultWindow(notification);
  71. childWindow.DataContext = notification;
  72. return childWindow;
  73. }
  74. private ChildWindow CreateDefaultWindow(Notification notification)
  75. {
  76. return notification is Confirmation
  77. ? (ChildWindow)new ConfirmationChildWindow { ConfirmationTemplate = this.ContentTemplate }
  78. : new NotificationChildWindow { NotificationTemplate = this.ContentTemplate };
  79. }
  80. }
  81. }