RadWindow dialogs not closing when pressing Esc

7 posts, 1 answers
  1. Jochovader
    Jochovader avatar
    6 posts
    Member since:
    Feb 2012

    Posted 18 May 2014 Link to this post

    Hi! 

    Is there any special setting to allow the user to close the dialog window pressing the esc key?

    Im using the latest (v.2014.1.331.1050)

    I hope you can help me

    Regards
    JLuis
  2. Answer
    Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 19 May 2014 Link to this post

    Hello JLuis,

    You can easily achieve the desired by implementing an attached property which subscribes to the KeyDown event of the RadAlert dialog. In the event handler you would need to get the Parent of the RadAlert and call its Close method. For your convenience I have attached a sample project which demonstrates the exact approach.

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
  4. Jochovader
    Jochovader avatar
    6 posts
    Member since:
    Feb 2012

    Posted 19 May 2014 in reply to Kalin Link to this post

    Hi

    One question: does this apply for out-of-browser apps? 
    For some reason the OnKeyDownEventHandler is not launching.

    Regads
    JLuis
  5. Jochovader
    Jochovader avatar
    6 posts
    Member since:
    Feb 2012

    Posted 19 May 2014 in reply to Jochovader Link to this post

    This is the style currently applied to the RadWindow.

    Do you think this interfere in some way with the helper?

    <Style TargetType="telerikNavigation:RadAlert"
                               BasedOn="{StaticResource RadAlertStyle}">
                            <Setter Property="IsTabStop"
                                    Value="false" />
                            <Setter Property="MinWidth"
                                    Value="275" />
                            <Setter Property="MaxWidth"
                                    Value="500" />
                            <Setter Property="helpers:DialogKeyHelper.IsKeyEnabled"
                                    Value="True" />
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="telerikNavigation:RadAlert">
                                        <Grid x:Name="LayoutRoot">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="*" />
                                                <RowDefinition Height="Auto" />
                                            </Grid.RowDefinitions>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>
                                            <telerik:CommandManager.InputBindings>
                                                <telerik:InputBindingCollection>
                                                    <telerik:KeyBinding Key="Escape"
                                                                        Command="telerik:WindowCommands.Confirm" />
                                                </telerik:InputBindingCollection>
                                            </telerik:CommandManager.InputBindings>
                                            <ContentPresenter x:Name="Icon"
                                                              VerticalAlignment="Top"
                                                              Margin="16 8 8 8"
                                                              ContentTemplate="{StaticResource AlertIconTemplate}" />
                                            <ScrollViewer IsTabStop="False"
                                                          Grid.Row="0"
                                                          Grid.Column="1"
                                                          HorizontalScrollBarVisibility="Auto"
                                                          VerticalScrollBarVisibility="Auto"
                                                          Margin="0 0 0 7"
                                                          BorderBrush="{x:Null}">
                                                <ContentPresenter x:Name="AlertText"
                                                                  Margin="8 8 8 0" />
                                            </ScrollViewer>
                                            <Border x:Name="HorizontalRule"
                                                    Grid.Row="1"
                                                    Grid.ColumnSpan="2"
                                                    Height="1"
                                                    Background="{StaticResource BasicBrush}"
                                                    VerticalAlignment="Top" />
                                            <telerik:RadButton x:Name="OK"
                                                               Command="telerik:WindowCommands.Confirm"
                                                               telerikNavigation:RadWindow.ResponseButton="Accept"
                                                               Grid.Row="2"
                                                               Grid.ColumnSpan="2"
                                                               MinWidth="70"
                                                               HorizontalAlignment="Right"
                                                               telerik:LocalizationManager.ResourceKey="Ok"
                                                               Margin="0 10 8 8" />
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
  6. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 20 May 2014 Link to this post

    Hi JLuis,

    I tested the provided Style with out of browser application and everything worked as expected. The Alert was closing when the escape button is pressed. I'm attaching the project here, please test it and let me know if it works for you, if not I'll ask you to modify it in order to reproduce your scenario.

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  7. Jochovader
    Jochovader avatar
    6 posts
    Member since:
    Feb 2012

    Posted 20 May 2014 in reply to Kalin Link to this post

    Hi! I'd found that I had a control catching all the key strokes before the attached property.
    The solution you provided works like a charm!

    thank you so much
  8. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 21 May 2014 Link to this post

    Hello JLuis,

    I'm glad you have managed to achieve the desired. If you have any further questions or concerns, please do not hesitate to contact us.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
DevCraft banner