BaseModalWindow.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Windows;
  3. namespace MediaBrowser.UI.Controls
  4. {
  5. /// <summary>
  6. /// Class BaseModalWindow
  7. /// </summary>
  8. public class BaseModalWindow : BaseWindow
  9. {
  10. /// <summary>
  11. /// Shows the modal.
  12. /// </summary>
  13. /// <param name="owner">The owner.</param>
  14. public void ShowModal(Window owner)
  15. {
  16. WindowStyle = WindowStyle.None;
  17. ResizeMode = ResizeMode.NoResize;
  18. ShowInTaskbar = false;
  19. WindowStartupLocation = WindowStartupLocation.Manual;
  20. AllowsTransparency = true;
  21. Width = owner.Width;
  22. Height = owner.Height;
  23. Top = owner.Top;
  24. Left = owner.Left;
  25. WindowState = owner.WindowState;
  26. Owner = owner;
  27. ShowDialog();
  28. }
  29. /// <summary>
  30. /// Called when [browser back].
  31. /// </summary>
  32. protected override void OnBrowserBack()
  33. {
  34. base.OnBrowserBack();
  35. CloseModal();
  36. }
  37. /// <summary>
  38. /// Raises the <see cref="E:System.Windows.FrameworkElement.Initialized" /> event. This method is invoked whenever <see cref="P:System.Windows.FrameworkElement.IsInitialized" /> is set to true internally.
  39. /// </summary>
  40. /// <param name="e">The <see cref="T:System.Windows.RoutedEventArgs" /> that contains the event data.</param>
  41. protected override void OnInitialized(EventArgs e)
  42. {
  43. base.OnInitialized(e);
  44. DataContext = this;
  45. }
  46. /// <summary>
  47. /// Closes the modal.
  48. /// </summary>
  49. protected virtual void CloseModal()
  50. {
  51. Close();
  52. }
  53. }
  54. }