0

我不知道这是否有效,但是否有机会将光标Textbox自动移动到一个位置(1 个空格键单击)。例如:我运行应用程序,光标在里面Textbox自动移动一个空格键

我的文本框:

<TextBox TextChanged="Searchbox_TextChanged" x:Name="Testing" Margin="2" Grid.Row="1" Text="{Binding SearchSmthg, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" Controls:TextboxHelper.ClearTextButton="True" Controls:TextboxHelper.Watermark="Search ..."/>
4

1 回答 1

0

使用CaretIndexFocusManager

  <Window x:Class="WpfApplication1.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window1" Height="300" Width="300">
        <Grid FocusManager.FocusedElement="{Binding ElementName=Focustext}">
            <TextBox x:Name="Focustext" Text=" " CaretIndex="1" MaxHeight="25"  />
        </Grid>
    </Window>

编辑:添加一个GotFocus事件处理程序并在CaretIndex=1那里设置

XAML:

<TextBox GotFocus="Testing_GotFocus"

代码背后:

private void Testing_GotFocus(object sender, RoutedEventArgs e)
        {
            //make sure your Textbox is not empty..
            Testing.CaretIndex = 1;
        }
于 2013-01-15T11:43:45.580 回答