From 5e15db58352d6be201cf7570ccf4016c0dfba29e Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Tue, 15 Feb 2011 21:45:03 +0000 Subject: [PATCH] ChildWindow: implemented properties that were previsouly not implemented such as OverlayBrush and OverlayOpacity which controls the look of the modal overlay when using the ChildWindow in a modal setting. Changed Caption property from type of string to type of object so now complex captions can be created using various XAML elements. --- .../ChildWindow/ChildWindow.cs | 119 ++++++++++++------ 1 file changed, 84 insertions(+), 35 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/ChildWindow.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/ChildWindow.cs index 3c6c4aba..727a85f8 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/ChildWindow.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/ChildWindow.cs @@ -40,8 +40,8 @@ namespace Microsoft.Windows.Controls public ChildWindow() { - _modalLayer.Fill = new SolidColorBrush(Colors.Gray); - _modalLayer.Opacity = 0.5; + _modalLayer.Fill = OverlayBrush; + _modalLayer.Opacity = OverlayOpacity; } #endregion //Constructors @@ -145,15 +145,21 @@ namespace Microsoft.Windows.Controls #endregion //Internal Properties - #region Dependency Properties + #region Public Properties - public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register("Caption", typeof(string), typeof(ChildWindow), new UIPropertyMetadata(String.Empty)); - public string Caption + #region Caption + + public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register("Caption", typeof(object), typeof(ChildWindow), new UIPropertyMetadata(String.Empty)); + public object Caption { - get { return (string)GetValue(CaptionProperty); } + get { return (object)GetValue(CaptionProperty); } set { SetValue(CaptionProperty, value); } } + #endregion //Caption + + #region CaptionForeground + public static readonly DependencyProperty CaptionForegroundProperty = DependencyProperty.Register("CaptionForeground", typeof(Brush), typeof(ChildWindow), new UIPropertyMetadata(null)); public Brush CaptionForeground { @@ -161,6 +167,10 @@ namespace Microsoft.Windows.Controls set { SetValue(CaptionForegroundProperty, value); } } + #endregion //CaptionForeground + + #region CloseButtonStyle + public static readonly DependencyProperty CloseButtonStyleProperty = DependencyProperty.Register("CloseButtonStyle", typeof(Style), typeof(ChildWindow), new PropertyMetadata(null)); public Style CloseButtonStyle { @@ -168,6 +178,10 @@ namespace Microsoft.Windows.Controls set { SetValue(CloseButtonStyleProperty, value); } } + #endregion //CloseButtonStyle + + #region CloseButtonVisibility + public static readonly DependencyProperty CloseButtonVisibilityProperty = DependencyProperty.Register("CloseButtonVisibility", typeof(Visibility), typeof(ChildWindow), new PropertyMetadata(Visibility.Visible)); public Visibility CloseButtonVisibility { @@ -175,13 +189,34 @@ namespace Microsoft.Windows.Controls set { SetValue(CloseButtonVisibilityProperty, value); } } - public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register("Icon", typeof(ImageSource), typeof(ChildWindow), new UIPropertyMetadata(default(ImageSource))); - public ImageSource Icon + #endregion //CloseButtonVisibility + + #region DialogResult + + private bool? _dialogResult; + /// + /// Gets or sets a value indicating whether the ChildWindow was accepted or canceled. + /// + /// + /// True if the child window was accepted; false if the child window was + /// canceled. The default is null. + /// + [TypeConverter(typeof(NullableBoolConverter))] + public bool? DialogResult { - get { return (ImageSource)GetValue(IconSourceProperty); } - set { SetValue(IconSourceProperty, value); } + get { return _dialogResult; } + set + { + if (_dialogResult != value) + { + _dialogResult = value; + Close(); + } + } } + #endregion //DialogResult + #region IsModal public static readonly DependencyProperty IsModalProperty = DependencyProperty.Register("IsModal", typeof(bool), typeof(ChildWindow), new UIPropertyMetadata(false, new PropertyChangedCallback(OnIsModalPropertyChanged))); @@ -240,24 +275,48 @@ namespace Microsoft.Windows.Controls #region OverlayBrush - public static readonly DependencyProperty OverlayBrushProperty = DependencyProperty.Register("OverlayBrush", typeof(Brush), typeof(ChildWindow)); + public static readonly DependencyProperty OverlayBrushProperty = DependencyProperty.Register("OverlayBrush", typeof(Brush), typeof(ChildWindow), new PropertyMetadata(Brushes.Gray, OnOverlayBrushChanged)); public Brush OverlayBrush { get { return (Brush)GetValue(OverlayBrushProperty); } set { SetValue(OverlayBrushProperty, value); } } + private static void OnOverlayBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ChildWindow childWindow = d as ChildWindow; + if (childWindow != null) + childWindow.OnOverlayBrushChanged((Brush)e.OldValue, (Brush)e.NewValue); + } + + protected virtual void OnOverlayBrushChanged(Brush oldValue, Brush newValue) + { + _modalLayer.Fill = newValue; + } + #endregion //OverlayBrush #region OverlayOpacity - public static readonly DependencyProperty OverlayOpacityProperty = DependencyProperty.Register("OverlayOpacity", typeof(double), typeof(ChildWindow)); + public static readonly DependencyProperty OverlayOpacityProperty = DependencyProperty.Register("OverlayOpacity", typeof(double), typeof(ChildWindow), new PropertyMetadata(0.5, OnOverlayOpacityChanged)); public double OverlayOpacity { get { return (double)GetValue(OverlayOpacityProperty); } set { SetValue(OverlayOpacityProperty, value); } } + private static void OnOverlayOpacityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ChildWindow childWindow = d as ChildWindow; + if (childWindow != null) + childWindow.OnOverlayOpacityChanged((double)e.OldValue, (double)e.NewValue); + } + + protected virtual void OnOverlayOpacityChanged(double oldValue, double newValue) + { + _modalLayer.Opacity = newValue; + } + #endregion //OverlayOpacity #region Top @@ -284,6 +343,8 @@ namespace Microsoft.Windows.Controls #endregion //TopProperty + #region WindowBackground + public static readonly DependencyProperty WindowBackgroundProperty = DependencyProperty.Register("WindowBackground", typeof(Brush), typeof(ChildWindow), new PropertyMetadata(null)); public Brush WindowBackground { @@ -291,6 +352,10 @@ namespace Microsoft.Windows.Controls set { SetValue(WindowBackgroundProperty, value); } } + #endregion //WindowBackground + + #region WindowBorderBrush + public static readonly DependencyProperty WindowBorderBrushProperty = DependencyProperty.Register("WindowBorderBrush", typeof(Brush), typeof(ChildWindow), new PropertyMetadata(null)); public Brush WindowBorderBrush { @@ -298,6 +363,10 @@ namespace Microsoft.Windows.Controls set { SetValue(WindowBorderBrushProperty, value); } } + #endregion //WindowBorderBrush + + #region WindowOpacity + public static readonly DependencyProperty WindowOpacityProperty = DependencyProperty.Register("WindowOpacity", typeof(double), typeof(ChildWindow), new PropertyMetadata(null)); public double WindowOpacity { @@ -305,6 +374,8 @@ namespace Microsoft.Windows.Controls set { SetValue(WindowOpacityProperty, value); } } + #endregion //WindowOpacity + #region WindowStartupLocation public static readonly DependencyProperty WindowStartupLocationProperty = DependencyProperty.Register("WindowStartupLocation", typeof(WindowStartupLocation), typeof(ChildWindow), new UIPropertyMetadata(WindowStartupLocation.Manual, OnWindowStartupLocationChanged)); @@ -345,29 +416,7 @@ namespace Microsoft.Windows.Controls #endregion //WindowState - #endregion //Dependency Properties - - private bool? _dialogResult; - /// - /// Gets or sets a value indicating whether the ChildWindow was accepted or canceled. - /// - /// - /// True if the child window was accepted; false if the child window was - /// canceled. The default is null. - /// - [TypeConverter(typeof(NullableBoolConverter))] - public bool? DialogResult - { - get { return _dialogResult; } - set - { - if (_dialogResult != value) - { - _dialogResult = value; - Close(); - } - } - } + #endregion //Public Properties #endregion //Properties