Skip to content

Commit

Permalink
Add EscToCloseBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzying2001 committed May 17, 2024
1 parent e36a966 commit e33a467
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CefFlashBrowser/CefFlashBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
<Compile Include="Models\ProxySettings.cs" />
<Compile Include="Models\UserAgentSetting.cs" />
<Compile Include="Utils\Behaviors\DropFileBehavior.cs" />
<Compile Include="Utils\Behaviors\EscToCloseBehavior.cs" />
<Compile Include="Utils\Converters\MultiValueConverterBase.cs" />
<Compile Include="Utils\Converters\ObjectNotNull.cs" />
<Compile Include="Utils\Converters\StringArrNotAnyEmpty.cs" />
Expand Down
27 changes: 27 additions & 0 deletions CefFlashBrowser/Utils/Behaviors/EscToCloseBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Xaml.Behaviors;
using System.Windows;
using System.Windows.Input;

namespace CefFlashBrowser.Utils.Behaviors
{
public class EscToCloseBehavior : Behavior<Window>
{
protected override void OnAttached()
{
AssociatedObject.KeyDown += KeyDownHandler;
}

protected override void OnDetaching()
{
AssociatedObject.KeyDown -= KeyDownHandler;
}

private void KeyDownHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
AssociatedObject.Close();
}
}
}
}
4 changes: 4 additions & 0 deletions CefFlashBrowser/Views/Dialogs/AddFavoriteDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
Title="{DynamicResource title_addFavorite}"
FocusManager.FocusedElement="{Binding ElementName=NameTextBox}">

<i:Interaction.Behaviors>
<behaviors:EscToCloseBehavior/>
</i:Interaction.Behaviors>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
Expand Down

0 comments on commit e33a467

Please sign in to comment.