Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to highlight text in textbox when it gets focus
    primarykey
    data
    text
    <p>This seems a simple question but I was not able to find the answer in the web. The only thing I want consists in to get the content hightlighted in the textbox, when the user gets in ('Price' or 'Quantity' in this example). Right now it's necessary double click first in order to edit the content. The content should be selected automatically when it get's focus. How can I do this?</p> <p>Thank you </p> <pre><code>&lt;Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="350" Width="479" Name="Window1"&gt; &lt;Window.Resources&gt; &lt;CollectionViewSource x:Key="MasterView" /&gt; &lt;CollectionViewSource Source="{Binding Source={StaticResource MasterView}, Path='OrderDetails'}" x:Key="DetailView" /&gt; &lt;CollectionViewSource x:Key="CustomerLookup" /&gt; &lt;CollectionViewSource x:Key="ProductLookup" /&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="42" /&gt; &lt;RowDefinition Height="110" /&gt; &lt;RowDefinition Height="42" /&gt; &lt;RowDefinition Height="147*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid Grid.Row="1" Name="Grid1"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="146*" /&gt; &lt;ColumnDefinition Width="346*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;StackPanel Name="StackPanel1" &gt; &lt;Label Height="28" Name="Label1" Width="Auto" HorizontalContentAlignment="Right"&gt;ID:&lt;/Label&gt; &lt;Label Height="28" Name="Label2" Width="Auto" HorizontalContentAlignment="Right"&gt;Customer:&lt;/Label&gt; &lt;Label Height="28" Name="Label3" Width="Auto" HorizontalContentAlignment="Right"&gt;Order Date:&lt;/Label&gt; &lt;Label Height="28" Name="Label4" Width="Auto" HorizontalContentAlignment="Right"&gt;Ship Date:&lt;/Label&gt; &lt;/StackPanel&gt; &lt;StackPanel Name="StackPanel2" Grid.Column="1" DataContext="{Binding Source={StaticResource MasterView}}"&gt; &lt;TextBox Height="23" Name="TextBox1" Width="100" Margin="2" HorizontalAlignment="Left" IsReadOnly="True" Text="{Binding Path=OrderID, Mode=OneWay}"/&gt; &lt;ComboBox Height="23" Name="ComboBox1" Width="177" Margin="2" HorizontalAlignment="Left" IsEditable="False" ItemsSource="{Binding Source={StaticResource CustomerLookup}}" SelectedValue="{Binding Path=CustomerID}" SelectedValuePath="CustomerID" DisplayMemberPath="Name"/&gt; &lt;TextBox Height="23" Name="TextBox3" Width="100" Margin="2" HorizontalAlignment="Left" Text="{Binding Path=OrderDate}"/&gt; &lt;TextBox Height="23" Name="TextBox4" Width="100" Margin="2" HorizontalAlignment="Left" Text="{Binding Path=ShipDate}"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;StackPanel Name="StackPanel3" Orientation="Horizontal"&gt; &lt;Button Height="25" Name="btnAdd" Width="Auto" Margin="3"&gt;Add Order&lt;/Button&gt; &lt;Button Height="25" Name="btnDelete" Width="Auto" Margin="3"&gt;Delete Order&lt;/Button&gt; &lt;Button Height="25" Name="btnPrevious" Width="75" Margin="3"&gt;Previous&lt;/Button&gt; &lt;Button Height="25" Name="btnNext" Width="75" Margin="3"&gt;Next&lt;/Button&gt; &lt;Button Height="25" Name="btnSave" Width="75" Margin="3"&gt;Save&lt;/Button&gt; &lt;/StackPanel&gt; &lt;StackPanel Name="StackPanel4" Orientation="Horizontal" Grid.Row="2"&gt; &lt;Button Height="25" Name="btnAddDetail" Width="Auto" Margin="3"&gt;Add Detail&lt;/Button&gt; &lt;Button Height="25" Name="btnDeleteDetail" Width="Auto" Margin="3"&gt;Delete Detail&lt;/Button&gt; &lt;/StackPanel&gt; &lt;ListView Grid.Row="3" Name="ListView1" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource DetailView}}"&gt; &lt;ListView.ItemContainerStyle&gt; &lt;Style TargetType="ListViewItem"&gt; &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt; &lt;EventSetter Event="GotFocus" Handler="Item_GotFocus" /&gt; &lt;/Style&gt; &lt;/ListView.ItemContainerStyle&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Header="ID" Width="75"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Label Content="{Binding Path=OrderDetailID}" Margin="-6,0,-6,0"/&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Header="OrderID" Width="75"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Label Content="{Binding Path=OrderID}" Margin="-6,0,-6,0"/&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Header="Product" Width="150"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox IsEditable="False" Name="cboProduct" IsSynchronizedWithCurrentItem="False" ItemsSource="{Binding Source={StaticResource ProductLookup}}" SelectedValue="{Binding Path=ProductID}" DisplayMemberPath="Name" SelectedValuePath="ProductID" Margin="-6,0,-6,0"/&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Header="Quantity" Width="75"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBox Text="{Binding Path=Quantity}" Margin="-6,0,-6,0"/&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Header="Price" Width="75"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBox Text="{Binding Path=Price}" Margin="-6,0,-6,0"/&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload