diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/ChildWindow.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/ChildWindow.cs index 842251f1..94c74047 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/ChildWindow.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/ChildWindow.cs @@ -6,11 +6,10 @@ using System.Windows.Media; using System.Windows.Controls.Primitives; using System.ComponentModel; using System.Windows.Shapes; +using System.Windows.Threading; namespace Microsoft.Windows.Controls { - [TemplateVisualState(GroupName = VisualStates.WindowStatesGroup, Name = VisualStates.Open)] - [TemplateVisualState(GroupName = VisualStates.WindowStatesGroup, Name = VisualStates.Closed)] public class ChildWindow : ContentControl { #region Private Members @@ -42,6 +41,8 @@ namespace Microsoft.Windows.Controls public ChildWindow() { + IsVisibleChanged += ChildWindow_IsVisibleChanged; + _modalLayer.Fill = OverlayBrush; _modalLayer.Opacity = OverlayOpacity; } @@ -98,8 +99,17 @@ namespace Microsoft.Windows.Controls } _root.Children.Add(_modalLayerPanel); + } - ChangeVisualState(); + protected override void OnGotFocus(RoutedEventArgs e) + { + Action action = () => + { + if (FocusedElement != null) + FocusedElement.Focus(); + }; + + Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, action); } protected override void OnKeyDown(KeyEventArgs e) @@ -219,6 +229,17 @@ namespace Microsoft.Windows.Controls #endregion //DialogResult + #region FocusedElement + + public static readonly DependencyProperty FocusedElementProperty = DependencyProperty.Register("FocusedElement", typeof(FrameworkElement), typeof(ChildWindow), new UIPropertyMetadata(null)); + public FrameworkElement FocusedElement + { + get { return (FrameworkElement)GetValue(FocusedElementProperty); } + set { SetValue(FocusedElementProperty, value); } + } + + #endregion + #region IsModal public static readonly DependencyProperty IsModalProperty = DependencyProperty.Register("IsModal", typeof(bool), typeof(ChildWindow), new UIPropertyMetadata(false, new PropertyChangedCallback(OnIsModalPropertyChanged))); @@ -431,6 +452,12 @@ namespace Microsoft.Windows.Controls #region Event Handlers + void ChildWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) + { + if ((bool)e.NewValue) + Focus(); + } + void HeaderLeftMouseButtonDown(object sender, MouseButtonEventArgs e) { e.Handled = true; @@ -548,8 +575,6 @@ namespace Microsoft.Windows.Controls break; } } - - ChangeVisualState(); //perform the close } private void ExecuteClose() @@ -600,8 +625,6 @@ namespace Microsoft.Windows.Controls if (IsModal) Canvas.SetZIndex(_modalLayerPanel, index - 2); - - Focus(); } private void CenterChildWindow() @@ -637,22 +660,6 @@ namespace Microsoft.Windows.Controls #endregion //Private - #region Protected - - protected virtual void ChangeVisualState() - { - if (WindowState == WindowState.Closed) - { - VisualStateManager.GoToState(this, VisualStates.Closed, true); - } - else - { - VisualStateManager.GoToState(this, VisualStates.Open, true); - } - } - - #endregion //Protected - #region Public public void Show() diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/VisualStates.ChildWindow.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/VisualStates.ChildWindow.cs deleted file mode 100644 index eb3a4ea9..00000000 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/VisualStates.ChildWindow.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Microsoft.Windows.Controls -{ - internal static partial class VisualStates - { - /// - /// Window State group name. - /// - public const string WindowStatesGroup = "WindowStatesGroup"; - - /// - /// Open state name for ChildWindow. - /// - public const string Open = "Open"; - - /// - /// Closed state name for ChildWindow. - /// - public const string Closed = "Closed"; - } -} diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Themes/Generic.xaml index cb158d61..6b8fea5f 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Themes/Generic.xaml @@ -136,34 +136,6 @@ - - - - - - - - - Collapsed - - - - - - - - - - - Visible - - - - - - - - @@ -226,6 +198,11 @@ + + + + + diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Themes/Generic.xaml index 96e1f751..93042685 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Themes/Generic.xaml @@ -146,7 +146,7 @@ - diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj index 71501abb..3c2f4bde 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj @@ -140,7 +140,6 @@ -