Note that there are some explanatory texts on larger screens.

plurals
  1. POInline editing TextBlock in a ListBox with Data Template (WPF)
    text
    copied!<p>Using WPF, I have a <code>ListBox</code> control with a <code>DataTemplate</code> inside it. The relevant XAML code is shown below:</p> <pre><code>&lt;ListBox Name="_todoList" Grid.Row="1" BorderThickness="2" Drop="todoList_Drop" AllowDrop="True" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AlternationCount="2"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid Margin="4"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;CheckBox Grid.Column="0" Checked="CheckBox_Check" /&gt; &lt;TextBlock Name="descriptionBlock" Grid.Column="1" Text="{Binding Description}" Cursor="Hand" FontSize="14" ToolTip="{Binding Description}" MouseDown="TextBlock_MouseDown" /&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>What I am trying to do is make the <code>TextBlock</code> respond to a (double)click which turns it into a <code>TextBox</code>. The user can then edit the description, and press return or change focus to make the change.</p> <p>I have tried adding a <code>TextBox</code> element in the same position as the TextBlock and making its visiblity <code>Collapsed</code>, but I don't know how to navigate to the right <code>TextBox</code> when the user has clicked on a <code>TextBlock</code>. That is, I know the user has clicked on a certain <code>TextBlock</code>, now <em>which</em> <code>TextBox</code> do I show?</p> <p>Any help would be appreciated greatly,</p> <p>-Ko9</p>
 

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