0
<Grid x:Name="LayoutRoot">
    <TextBox x:Name="txt_remove" Height="46" Margin="234,119,225,0" TextWrapping="Wrap" VerticalAlignment="Top" GotFocus="txt_remove_GotFocus"/>
    <RepeatButton x:Name="rbtn_remove" Content="Remove" Delay="500" Interval="100"  Margin="283.667,183,282.333,222" RenderTransformOrigin="0.667,0.854" Click="rbtn_remove_Click" />                  
</Grid>

C#のコード

public partial class Repeate : Window
{
    Control GetTextbox;

    public Repeate()
    {
        this.InitializeComponent(); 

    }

    private void rbtn_remove_Click(object sender, RoutedEventArgs e)
    {

         TextBox 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;
                GetInstance.Focus();
                GetInstance.CaretIndex = _CareIndex - 1;
            }
        }
    }

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

}

上記のコードで、私は以下の結果を得ることができます。

RepeatButton

[削除]ボタンをクリックすると、テキストボックスの値がクリアされますが、[削除]ボタンをクリックして押したままにすると、テキストボックスの値が繰り返し削除されません

4

1 に答える 1

2

あなたがやりたい仕事をするのにすべてが十分です。ただし、Getinstance で focus() メソッドを呼び出します。差をつけています。

削除するだけです。

GetInstance.Focus();

動作します。

于 2012-08-01T08:57:35.333 に答える