Browse Source

ChildWindow: added FocusedElement property that will allow you to set the initial focused element when the ChildWindow is shown/receives focus.

FocusedElement="{Binding ElementName=_textBox}"
pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
20ca224b52
  1. 53
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/ChildWindow.cs
  2. 22
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/VisualStates.ChildWindow.cs
  3. 33
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Themes/Generic.xaml
  4. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Themes/Generic.xaml
  5. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

53
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()

22
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Implementation/VisualStates.ChildWindow.cs

@ -1,22 +0,0 @@
using System;
namespace Microsoft.Windows.Controls
{
internal static partial class VisualStates
{
/// <summary>
/// Window State group name.
/// </summary>
public const string WindowStatesGroup = "WindowStatesGroup";
/// <summary>
/// Open state name for ChildWindow.
/// </summary>
public const string Open = "Open";
/// <summary>
/// Closed state name for ChildWindow.
/// </summary>
public const string Closed = "Closed";
}
}

33
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ChildWindow/Themes/Generic.xaml

@ -136,34 +136,6 @@
</Style>
</Grid.Resources>
<!--VisualStateManager-->
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="WindowStatesGroup">
<VisualState x:Name="Closed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Root" Storyboard.TargetProperty="Visibility" Duration="0">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Open">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Root" Storyboard.TargetProperty="Visibility" Duration="0">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="PART_WindowRoot" HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="{TemplateBinding MinWidth}" MinHeight="{TemplateBinding MinHeight}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" >
<Grid.RenderTransform>
<TransformGroup>
@ -226,6 +198,11 @@
</Border>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="WindowState" Value="Closed">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Themes/Generic.xaml

@ -146,7 +146,7 @@
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorPicker}">
<Grid>
<ToggleButton x:Name="PART_ColorPickerToggleButton" IsTabStop="False" MinHeight="22" IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
<ToggleButton x:Name="PART_ColorPickerToggleButton" IsTabStop="True" MinHeight="22" IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
IsHitTestVisible="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}}"
Style="{TemplateBinding ButtonStyle}">
<Grid Margin="2,2,0,2">

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -140,7 +140,6 @@
<Compile Include="BusyIndicator\Implementation\BusyIndicator.cs" />
<Compile Include="ButtonSpinner\Implementation\ButtonSpinner.cs" />
<Compile Include="ChildWindow\Implementation\ChildWindow.cs" />
<Compile Include="ChildWindow\Implementation\VisualStates.ChildWindow.cs" />
<Compile Include="ChildWindow\Implementation\WindowStartupLocation.cs" />
<Compile Include="ChildWindow\Implementation\WindowState.cs" />
<Compile Include="ButtonSpinner\Implementation\SpinDirection.cs" />

Loading…
Cancel
Save