Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should work fine with a simple DataTrigger.</p> <p>Your Object Class:</p> <pre><code>public class TestObject { public string Name { get; set; } public bool IsHighlighted { get; set; } public override string ToString() { return this.Name; } } </code></pre> <p>Xaml:</p> <pre><code>&lt;Window x:Class="TestWPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestWPF" Title="MainWindow"&gt; &lt;Grid&gt; &lt;StackPanel&gt; &lt;ComboBox&gt; &lt;ComboBox.Resources&gt; &lt;Style TargetType="ComboBoxItem"&gt; &lt;Setter Property="FocusVisualStyle" Value="{x:Null}" /&gt; &lt;Setter Property="Background" Value="Gray" /&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding IsHighlighted}" Value="True"&gt; &lt;Setter Property="Background" Value="Red" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ComboBox.Resources&gt; &lt;local:Employee Name="Nick" /&gt; &lt;local:Employee Name="Bob" IsHighlighted="True" /&gt; &lt;local:Employee Name="Fred" /&gt; &lt;/ComboBox&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Note: Unlike the sample above, I'm guessing in your code you're binding the combobox's ItemsSource... which should work just the same. One thing to be careful of though, is if your object's 'IsHighlighted' property can change, you should be implementing INotifyProperty changed to ensure that changing the value will notify the UI that the triggers should refresh.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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