Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Label to Textbox
    primarykey
    data
    text
    <p>Im pretty noob in WPF but im seriously trying to master it :p</p> <p>Ive been trying to create a control where one label/textblock is displayed but once the user hovers/clicks the control, a textbox is shown instead so the value can be edited.</p> <p>What i have been trying is binding the Visible property to a boolean in the code-behind, which is updated using delegates for MouseOver and MouseLeave and Got/LostFocus, but it didnt work. Also i tried using a simple style which also bound the Visible property to the boolean in code-behind... didnt work either. Ultimately, i followed what <a href="https://stackoverflow.com/questions/2583219">WPF: Label to TextBox when selected</a> suggested, using a ControlTemplate and a Trigger, like this:</p> <pre><code> &lt;Style x:Key="TransformerBox" TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="true"&gt; &lt;Setter Property="Visibility" Value="Visible"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>And:</p> <pre><code> &lt;Canvas x:Name="CnvCantidad" Grid.Row="2" Grid.Column="1"&gt; &lt;TextBox HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="16" Canvas.Top="8" Width="16" x:Name="TxtCantidad" Style="{StaticResource TransformerBox}" Height="23" Visibility="Visible"/&gt; &lt;Label HorizontalAlignment="Center" VerticalAlignment="Center" Content="0" Canvas.Left="16" Canvas.Top="6" x:Name="LblCantidad"/&gt; &lt;/Canvas&gt; </code></pre> <p>But in all the cases explained before, the TextBox was never visible no matter what :/</p> <p>How should i create the ControlTemplate so the TextBox is visible when the user hovers the Label/TextBlock?</p>
    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