Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a virtual slider as a WPF-CustomControl that combines a Button with a TextBox
    primarykey
    data
    text
    <p>I want to implement a WPF CustomControl, that...</p> <ol> <li>Normally looks like a button and displays a float value as string</li> <li>When dragging the button the float value is being manipulated like a virtual slider</li> <li>When clicking the button, it is replaced by a TextBox, prefilled with the current Value as String. This text can be edited. Clicking outside of the TextBox or pressing return will change the control back to Button and use the edited text as the new Value.</li> </ol> <p>We need this control in a highly streamlined interface. Although the description sounds a little weird, it works amazingly well for us. But for performance reasons we now have to refactor the current implementation as a UserControl into a CustomControl.</p> <p>I got the slider-part of the control running and managed to show a TextBox attached to a Content DependencyProperty. Sadly, however, I fail to access this TextBox from the ControlTemplate, which looks roughly like this:</p> <pre><code>&lt;Style TargetType="{x:Type local:FloatEditButton}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type local:FloatEditButton}"&gt; &lt;Grid Margin="0"&gt; &lt;Viewbox VerticalAlignment="Center" HorizontalAlignment="{Binding RelativeSource={RelativeSource TemplatedParent},Path=HorizontalContentAlignment}" Margin="0"&gt; &lt;ContentPresenter Name="content" Margin="2" VerticalAlignment="Center" /&gt; &lt;/Viewbox&gt; &lt;TextBox x:Name="XTextBox" Visibility="Collapsed" Text="{Binding Content}"/&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="EditingAsTextBox" Value="True"&gt; &lt;Setter TargetName="XTextBox" 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>Any idea, how this could be implemented as a CustomControl?</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.
    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