Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:55:53+00:00 2026-06-09T07:55:53+00:00

<Grid x:Name=BackSpaceButton> <TextBox x:Name=txt_remove Height=46 Margin=234,119,225,0 TextWrapping=Wrap VerticalAlignment=Top GotFocus=txt_remove_GotFocus TabIndex=2/> <RepeatButton x:Name=rbtn_remove Content=Backspace Delay=400

  • 0
 <Grid x:Name="BackSpaceButton">       
    <TextBox x:Name="txt_remove" Height="46" Margin="234,119,225,0" TextWrapping="Wrap" VerticalAlignment="Top" GotFocus="txt_remove_GotFocus" TabIndex="2"/>        
    <RepeatButton x:Name="rbtn_remove" Content="Backspace" Delay="400" Interval="200" Margin="415,124,0,0" RenderTransformOrigin="0.667,0.854" Click="rbtn_remove_Click" LostMouseCapture="rbtn_remove_LostMouseCapture" HorizontalAlignment="Left" Height="41" VerticalAlignment="Top" Width="66" TabIndex="2" />        
</Grid>

This design will be like below

enter image description here

public partial class Repeate : Window
{
    Control GetTextbox;
    TextBox GetInstance;
    public Repeate()
    {
        this.InitializeComponent();
    }

    private void rbtn_remove_Click(object sender, RoutedEventArgs e)
    {

        GetInstance = GetTextbox as TextBox;
        if (GetTextbox != null)
        {

            string _CurrentValue = GetInstance.Text;
            var _CareIndex = GetInstance.CaretIndex;

            if (_CareIndex > 0)
            {
                string _Backspace = _CurrentValue.Remove(_CareIndex - 1, 1);
                GetInstance.Text = _Backspace; 
                // I want o remove the Gotfocus envet here.  
                GetInstance.Focus(); //If i comment this line cursor will not focus on textbox
                GetInstance.CaretIndex = _CareIndex - 1;
            }
        }
    }

    private void txt_remove_GotFocus(object sender, RoutedEventArgs e)
    {
        GetTextbox = (Control)sender;
    }

    private void rbtn_remove_LostMouseCapture(object sender, MouseEventArgs e)
    {
        GetInstance.Focus();
    }


}

Out put will be like below

enter image description here

When i click the Backspace button textbox will remove and the cursor will be focusing in textbox.What is the issue is, when i click and hold the Backspace button the textbox value in not removing repeatedly. If comment the GetInstance.Focus(); from above code the values are removing repeatedly but the cursor in not focusing when repeatedly removing the text value on textbox.

But i have an idea if remove the event(txt_remove_GotFocus) before GetInstance.Focus();, the textbox values are removing repeatedly when click and hold the Backspace button.After then will add new event handler in rbtn_remove_LostMouseCapture envent.

Finaly i want to achieve the below scenario.

For Ex: Enter the value in textbox and then click and hold the backspace key from your system keyboard then you will fee the difference.

If you any other idea means for above scenario, Please share with me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:55:55+00:00Added an answer on June 9, 2026 at 7:55 am

    Why don’t you use RepeatButton class?

    Citation from MSDN:

    Represents a control that raises its Click event repeatedly from the
    time it is pressed until it is released.

    Here’s MVVM-way code sample:

    1) Sample view model:

    public class ViewModel : ViewModelBase
    {
        public ViewModel()
        {
            this.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
            this.backspaceCommand = new RelayCommand(
                () => Text = Text.Substring(0, Text.Length - 1), 
                () => !String.IsNullOrEmpty(Text));
        }
    
        public String Text
        {
            get { return text; }
            set
            {
                if (text != value)
                {
                    text = value;
                    OnPropertyChanged("Text");
                }
            }
        }
        private String text;
    
        public RelayCommand BackspaceCommand
        {
            get { return backspaceCommand; }
        }
        private readonly RelayCommand backspaceCommand;
    }
    

    3) Window markup:

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="114" Width="404">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
    
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
    
            <TextBox Grid.Column="0" Margin="5" x:Name="tbText" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"/>
            <RepeatButton Grid.Column="1" Margin="5" Content="Backspace" Command="{Binding BackspaceCommand}"/>
        </Grid>
    </Window>
    

    3) Window code-behind:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += (sender, args) => 
            { 
                tbText.Focus(); 
                tbText.CaretIndex = tbText.Text.Length; 
            };
            DataContext = new ViewModel();
        }
    }
    

    Here’s ugly code-behind-way sample:

    UPDATE.
    This sample has been updated to show caret, when button is pressed.
    The first, we should disable focusing on the button. The second, we should fix caret position after the text in TextBox was changed.

    1) Windows markup:

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="114" Width="404">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
    
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
    
            <TextBox Grid.Column="0" Margin="5" x:Name="tbText" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit."/>
            <RepeatButton Grid.Column="1" Margin="5" Focusable="False" Content="Backspace" Click="RepeatButton_Click"/>
        </Grid>
    </Window>
    

    2) Window code-behind:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += (sender, args) => 
            { 
                tbText.Focus(); 
                tbText.CaretIndex = tbText.Text.Length; 
            };
        }
    
        private void RepeatButton_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(tbText.Text))
            {
                tbText.Text = tbText.Text.Substring(0, tbText.Text.Length - 1);
                tbText.CaretIndex = tbText.Text.Length;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i just want to find out the name of this grid to refresh it.
I'm using jqgrid tree grid with the following configuration colModel : [ { name:'id',width
I have a grid. Inside the grid I have a column name as Document
I'm using .NET webforms. I have a grid view that can use Eval(Name) in
I could create a grid with telerik mvc <% Html.Telerik().Grid(Model) .Name(ProductGrid) .Columns(columns => {
I have the following markup. @(Html.Telerik().Grid(Model) .Name(Grid) .DataKeys(keys => keys.Add(key => key.Id)) .Columns(columns =>
mai is the grid name that contains the image, text and small image. I
I have a grid containing name and value columns. In value column I want
I have this in my code: @model Tuple<IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>> @(Html.Telerik().Grid(Model.Item3) .Name(Grid) .DataKeys(keys =>
I'm using grid that looks like that: Html.Telerik().Grid(Model).Name(preciousGrid). ... bla bla bla.. .ClientEvents(events =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.