I am trying to set the cursor / cursor position to the end of a string value in a WPF text box when I open my window for the first time. I use FocusManager to adjust the focus on my text box when my window opens.
Nothing seems to work. Any ideas?
Notice that I am using the MVVM pattern, and I only included the XAML part from my code.
<Window FocusManager.FocusedElement="{Binding ElementName=NumberOfDigits}" Height="400" Width="800"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBox Grid.Column="0" Grid.Row="0" x:Name="NumberOfDigits" IsReadOnly="{Binding Path=IsRunning, Mode=TwoWay}" VerticalContentAlignment="Center" Text="{Binding Path=Digits, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> <Button Grid.Column="0" Grid.Row="1" Margin="10,0,10,0" IsDefault="True" Content="Start" Command="{Binding StartCommand}"/> </Grid> </Window>
wpf cursor caret cursor-position textbox
Zamboni May 22 '10 at 16:49 2010-05-22 16:49
source share