Browse Source

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.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
5e15db5835
  1. 119
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/ChildWindow.cs

119
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/ChildWindow.cs

@ -40,8 +40,8 @@ namespace Microsoft.Windows.Controls
public ChildWindow() public ChildWindow()
{ {
_modalLayer.Fill = new SolidColorBrush(Colors.Gray); _modalLayer.Fill = OverlayBrush;
_modalLayer.Opacity = 0.5; _modalLayer.Opacity = OverlayOpacity;
} }
#endregion //Constructors #endregion //Constructors
@ -145,15 +145,21 @@ namespace Microsoft.Windows.Controls
#endregion //Internal Properties #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)); #region Caption
public string 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); } set { SetValue(CaptionProperty, value); }
} }
#endregion //Caption
#region CaptionForeground
public static readonly DependencyProperty CaptionForegroundProperty = DependencyProperty.Register("CaptionForeground", typeof(Brush), typeof(ChildWindow), new UIPropertyMetadata(null)); public static readonly DependencyProperty CaptionForegroundProperty = DependencyProperty.Register("CaptionForeground", typeof(Brush), typeof(ChildWindow), new UIPropertyMetadata(null));
public Brush CaptionForeground public Brush CaptionForeground
{ {
@ -161,6 +167,10 @@ namespace Microsoft.Windows.Controls
set { SetValue(CaptionForegroundProperty, value); } set { SetValue(CaptionForegroundProperty, value); }
} }
#endregion //CaptionForeground
#region CloseButtonStyle
public static readonly DependencyProperty CloseButtonStyleProperty = DependencyProperty.Register("CloseButtonStyle", typeof(Style), typeof(ChildWindow), new PropertyMetadata(null)); public static readonly DependencyProperty CloseButtonStyleProperty = DependencyProperty.Register("CloseButtonStyle", typeof(Style), typeof(ChildWindow), new PropertyMetadata(null));
public Style CloseButtonStyle public Style CloseButtonStyle
{ {
@ -168,6 +178,10 @@ namespace Microsoft.Windows.Controls
set { SetValue(CloseButtonStyleProperty, value); } 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 static readonly DependencyProperty CloseButtonVisibilityProperty = DependencyProperty.Register("CloseButtonVisibility", typeof(Visibility), typeof(ChildWindow), new PropertyMetadata(Visibility.Visible));
public Visibility CloseButtonVisibility public Visibility CloseButtonVisibility
{ {
@ -175,13 +189,34 @@ namespace Microsoft.Windows.Controls
set { SetValue(CloseButtonVisibilityProperty, value); } set { SetValue(CloseButtonVisibilityProperty, value); }
} }
public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register("Icon", typeof(ImageSource), typeof(ChildWindow), new UIPropertyMetadata(default(ImageSource))); #endregion //CloseButtonVisibility
public ImageSource Icon
#region DialogResult
private bool? _dialogResult;
/// <summary>
/// Gets or sets a value indicating whether the ChildWindow was accepted or canceled.
/// </summary>
/// <value>
/// True if the child window was accepted; false if the child window was
/// canceled. The default is null.
/// </value>
[TypeConverter(typeof(NullableBoolConverter))]
public bool? DialogResult
{ {
get { return (ImageSource)GetValue(IconSourceProperty); } get { return _dialogResult; }
set { SetValue(IconSourceProperty, value); } set
{
if (_dialogResult != value)
{
_dialogResult = value;
Close();
}
}
} }
#endregion //DialogResult
#region IsModal #region IsModal
public static readonly DependencyProperty IsModalProperty = DependencyProperty.Register("IsModal", typeof(bool), typeof(ChildWindow), new UIPropertyMetadata(false, new PropertyChangedCallback(OnIsModalPropertyChanged))); 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 #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 public Brush OverlayBrush
{ {
get { return (Brush)GetValue(OverlayBrushProperty); } get { return (Brush)GetValue(OverlayBrushProperty); }
set { SetValue(OverlayBrushProperty, value); } 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 #endregion //OverlayBrush
#region OverlayOpacity #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 public double OverlayOpacity
{ {
get { return (double)GetValue(OverlayOpacityProperty); } get { return (double)GetValue(OverlayOpacityProperty); }
set { SetValue(OverlayOpacityProperty, value); } 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 #endregion //OverlayOpacity
#region Top #region Top
@ -284,6 +343,8 @@ namespace Microsoft.Windows.Controls
#endregion //TopProperty #endregion //TopProperty
#region WindowBackground
public static readonly DependencyProperty WindowBackgroundProperty = DependencyProperty.Register("WindowBackground", typeof(Brush), typeof(ChildWindow), new PropertyMetadata(null)); public static readonly DependencyProperty WindowBackgroundProperty = DependencyProperty.Register("WindowBackground", typeof(Brush), typeof(ChildWindow), new PropertyMetadata(null));
public Brush WindowBackground public Brush WindowBackground
{ {
@ -291,6 +352,10 @@ namespace Microsoft.Windows.Controls
set { SetValue(WindowBackgroundProperty, value); } set { SetValue(WindowBackgroundProperty, value); }
} }
#endregion //WindowBackground
#region WindowBorderBrush
public static readonly DependencyProperty WindowBorderBrushProperty = DependencyProperty.Register("WindowBorderBrush", typeof(Brush), typeof(ChildWindow), new PropertyMetadata(null)); public static readonly DependencyProperty WindowBorderBrushProperty = DependencyProperty.Register("WindowBorderBrush", typeof(Brush), typeof(ChildWindow), new PropertyMetadata(null));
public Brush WindowBorderBrush public Brush WindowBorderBrush
{ {
@ -298,6 +363,10 @@ namespace Microsoft.Windows.Controls
set { SetValue(WindowBorderBrushProperty, value); } set { SetValue(WindowBorderBrushProperty, value); }
} }
#endregion //WindowBorderBrush
#region WindowOpacity
public static readonly DependencyProperty WindowOpacityProperty = DependencyProperty.Register("WindowOpacity", typeof(double), typeof(ChildWindow), new PropertyMetadata(null)); public static readonly DependencyProperty WindowOpacityProperty = DependencyProperty.Register("WindowOpacity", typeof(double), typeof(ChildWindow), new PropertyMetadata(null));
public double WindowOpacity public double WindowOpacity
{ {
@ -305,6 +374,8 @@ namespace Microsoft.Windows.Controls
set { SetValue(WindowOpacityProperty, value); } set { SetValue(WindowOpacityProperty, value); }
} }
#endregion //WindowOpacity
#region WindowStartupLocation #region WindowStartupLocation
public static readonly DependencyProperty WindowStartupLocationProperty = DependencyProperty.Register("WindowStartupLocation", typeof(WindowStartupLocation), typeof(ChildWindow), new UIPropertyMetadata(WindowStartupLocation.Manual, OnWindowStartupLocationChanged)); 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 //WindowState
#endregion //Dependency Properties #endregion //Public Properties
private bool? _dialogResult;
/// <summary>
/// Gets or sets a value indicating whether the ChildWindow was accepted or canceled.
/// </summary>
/// <value>
/// True if the child window was accepted; false if the child window was
/// canceled. The default is null.
/// </value>
[TypeConverter(typeof(NullableBoolConverter))]
public bool? DialogResult
{
get { return _dialogResult; }
set
{
if (_dialogResult != value)
{
_dialogResult = value;
Close();
}
}
}
#endregion //Properties #endregion //Properties

Loading…
Cancel
Save