Note that there are some explanatory texts on larger screens.

plurals
  1. POStyling a combobox's PART_EditableTextBox
    primarykey
    data
    text
    <p>I want to add conditionnal formatting (just font color) to the textbox part of a combobox. According to MSDN, it's the "PART_EditableTextBox" element. A quick search on SO got me started but I now face a problem: it overrides the whole template. According to <a href="https://stackoverflow.com/a/12011848/1991423">this SO answer</a>, I can use "BasedOn" to override only specific properties but I've no idea how/where to use it. This is my current template:</p> <pre><code> &lt;ControlTemplate x:Key="MyComboBoxTextBox" TargetType="ComboBox" &lt;!--Here?--&gt; &gt; &lt;TextBox x:Name="PART_EditableTextBox" &lt;!--Maybe Here?--&gt;&gt; &lt;TextBox.Style&gt; &lt;Style TargetType="TextBox"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Text" Value="MAL"&gt; &lt;Setter Property="Foreground" Value="DarkOrange"&gt;&lt;/Setter&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/TextBox.Style&gt; &lt;/TextBox&gt; &lt;/ControlTemplate&gt; </code></pre> <p>It works, I can still type in valid values and "MAL" does make the text orange but there's no dropdown anymore. On MSDN, I found the following:</p> <pre><code>&lt;TextBox x:Name="PART_EditableTextBox" Style="{x:Null}" Template="{StaticResource ComboBoxTextBox}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="3,3,23,3" Focusable="True" Background="Transparent" Visibility="Hidden" IsReadOnly="{TemplateBinding IsReadOnly}" /&gt; </code></pre> <p>I suppose I should base my template on this "ComboBoxTextBox" but I don't know how to reference it. Do I really need to copy the whole template or is there a way to override a specific property?</p> <p>EDIT: On the same MSDN page comboboxTextBox is defined as</p> <pre><code>&lt;ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}"&gt; &lt;Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" /&gt; &lt;/ControlTemplate&gt; </code></pre> <p>I don't see how overriding this template removes the dropdown list.</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