Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As I told you in your last (now duplicated) question, you will need to define a new <code>ControlTemplate</code> to achieve your goal. </p> <p>For future reference:</p> <blockquote> <p>Asking duplicate questions on StackOverflow is <em>not</em> approved by the community, <em>especially if you are asking a duplicate of your own question</em>. If you do not understand your answer(s) or do not feel that they answer your question adequately, you should ask the answer author(s) to explain it further in <em>that</em> question. </p> </blockquote> <p>Now I'll get off my soap box and get you further on your way to achieving your goal. As I said, you will need to define a new <code>ControlTemplate</code>... there is no way around this. The reason for this is simple - you want to add <code>Trigger</code>s to affect the XAML controls that are defined <em>inside</em> the default <code>ControlTemplate</code>, but you have no other way to do this from XAML.</p> <p>So, how do we define a new <code>ControlTemplate</code>? It's quite simple really: we just define some XAML in the <code>Template</code> property that describes the way that we want the control to look and behave. Please refer to the link that I provided you with for help with this in your last post. Additionally, here is a <em>very</em> simplified example:</p> <pre><code>&lt;Style TargetType="{x:Type ComboBox}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type ComboBox}"&gt; &lt;Border Name="Border" CornerRadius="2" Padding="2"&gt; &lt;ScrollViewer Margin="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"&gt; &lt;ItemsPresenter /&gt; &lt;/ScrollViewer&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsEnabled" Value="False"&gt; &lt;Setter TargetName="Border" Property="Background" Value="Red"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>Apply this <code>Style</code> to a <code>ComboBox</code> with the <code>IsEnabled</code> property set to <code>False</code> and you will see that it is red. Now you're probably thinking 'that doesn't look like a <code>ComboBox</code>' and you'd be right. That's because I just replaced all of the XAML from the default <code>ComboBox</code> <code>ControlTemplate</code> with a little bit that slightly resembles just the drop down section for simplicity.</p> <p>Your job now is to define your own <code>ControlTemplate</code> that replicates the default XAML and adds the relevant <code>Trigger</code>s that I have shown you in this and your last post. In the example, notice how the <code>Trigger.TargetName</code> is set to <code>Border</code>, which is the name of the internal <code>Border</code> control used. You will need to do this for each element that you want to colour.</p> <p>Here is a link to the default <code>ControlTemplate</code> for the <code>ComboBox</code> control. When you see how large it is, you will understand why I didn't use it in the example.</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms752094.aspx" rel="nofollow">ComboBox Styles and Templates</a></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