Preventing Expander to expand on enter keypress

3 posts, 1 answers
  1. Mitja Fortuna
    Mitja Fortuna avatar
    2 posts
    Member since:
    May 2008

    Posted 08 May 2009 Link to this post

    Hi.
    I have this kind of xaml code:
        <Grid x:Name="LayoutRoot" Background="White"
            <telerik:RadExpander x:Name="radExpander" ExpandDirection="Down" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                <telerik:RadExpander.Header > 
                    <StackPanel Orientation="Horizontal"
                        <TextBlock Name="tbBasicSearch" Text="Filter: Tax Number or Title:" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
                        <TextBox Height="Auto" Width="115" KeyDown="txt_KeyDown"  x:Name="txtOsnovniPogojKons" Style="{StaticResource TextBoxStyle}" Margin="5,0,0,0"/> 
                    </StackPanel> 
                </telerik:RadExpander.Header> 
                <telerik:RadExpander.Content> 
                    <telerik:RadWrapPanel Orientation="Horizontal"
                        <Grid Style="{StaticResource GridRadWraper}" > 
                            <TextBlock Margin="2,2,85,0" x:Name="lblID" Style="{StaticResource LabelStyle}" Text="ID" HorizontalAlignment="Right"/> 
                            <TextBox Margin="100,0,0,0" Text=""  KeyDown="txt_KeyDown"  x:Name="txtID" Style="{StaticResource TextBoxStyle}" TabIndex="1"   Width="80"/> 
                        </Grid> 
                        <Grid Style="{StaticResource GridRadWraper}"
                            <TextBlock TextWrapping="Wrap" Margin="2,2,85,0" x:Name="lblTitle" Style="{StaticResource LabelStyle}" Text="Title" Height="Auto" HorizontalAlignment="Right"/> 
                            <TextBox Height="Auto" Margin="100,0,0,0" KeyDown="txt_KeyDown" Text="" x:Name="txtTitle" Style="{StaticResource TextBoxStyle}" TabIndex="2" Width="80" /> 
                        </Grid> 
                        <Grid Style="{StaticResource GridRadWraper}"
                            <TextBlock Margin="2,2,85,6" Text="City" TextWrapping="Wrap" x:Name="lblCity" Style="{StaticResource LabelStyle}" Height="Auto" Width="Auto"  HorizontalAlignment="Right"/> 
                            <TextBox Height="Auto" Margin="100,0,0,0" KeyDown="txt_KeyDown" Text="" x:Name="txtCity" Style="{StaticResource TextBoxStyle}" TabIndex="4" Width="80"/> 
                        </Grid> 
                        <Grid Style="{StaticResource GridRadWraper}"
                            <TextBlock Margin="2,2,85,0" Text="Tax" TextWrapping="Wrap" x:Name="lblTax" Style="{StaticResource LabelStyle}" ToolTipService.ToolTip="Tax number" Height="Auto" HorizontalAlignment="Right"/> 
                            <TextBox Height="Auto" Margin="100,0,0,0" Text="" KeyDown="txt_KeyDown" x:Name="txtTax" Style="{StaticResource TextBoxStyle}" TabIndex="5" Width="80"/> 
                        </Grid> 
                        <Grid Style="{StaticResource GridRadWraper}"
     
                            <TextBlock Text="Swift code" Margin="2,2,85,0" x:Name="lblSwift" Style="{StaticResource LabelStyle}" Height="Auto" Width="Auto" HorizontalAlignment="Right" /> 
     
                            <TextBox Height="Auto" Text=""  x:Name="txtSwift" KeyDown="txt_KeyDown" Style="{StaticResource TextBoxStyle}"  Width="80" TabIndex="6" HorizontalAlignment="Right" Margin="100,0,0,0"/> 
                        </Grid> 
                        <Grid Style="{StaticResource GridRadWraper}"
                            <TextBlock Text="Regist. number" x:Name="lblRegistrationNumber" Style="{StaticResource LabelStyle}"  Margin="2,2,85,0" Height="Auto" HorizontalAlignment="Right"/> 
                            <TextBox Height="Auto" Margin="100,0,0,0" Text=""  KeyDown="txt_KeyDown" x:Name="txtRegistrationNumber" Style="{StaticResource TextBoxStyle}"  Width="80" TabIndex="7" HorizontalAlignment="Right"/> 
                        </Grid> 
                    </telerik:RadWrapPanel> 
                </telerik:RadExpander.Content> 
            </telerik:RadExpander> 
        </Grid> 
    When I  write something in tbBasicSearch textbox (in Expander's header) and then hit enter key, the Expander expands. I would like that it expands only when I click on the expand button and not when I press the enter key. Is this posible?

    I was also wondering if it's posible to show the content of Expander's header on the right side of expand button?
  2. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 08 May 2009 Link to this post

    Hi Mitja,

    You need to handle the KeyDown event like so:

    private void TextBox_KeyDown(object sender, KeyEventArgs e)  
    {  
        if (e.Key == Key.Enter)  
        {  
            //Do Search.  
            e.Handled = true;  
        }  

    <telerik:RadExpander> 
        <telerik:RadExpander.Header> 
            <TextBox Text="Search" KeyDown="TextBox_KeyDown" /> 
        </telerik:RadExpander.Header> 
    </telerik:RadExpander> 

    For your second question:
     
    Have you tried the different ExpandDirections?

    If you need, to change the layout, you can always edit the RadExpander ControlTemplate and change everything there.

    Hopefully this is what you need,

    Sincerely yours,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Mitja Fortuna
    Mitja Fortuna avatar
    2 posts
    Member since:
    May 2008

    Posted 08 May 2009 Link to this post

    Thank you. Your answer was very helpful. I also thank you for fast reply.
Back to Top