I am trying to change the value of ComboBoxItem based on the property value assigned to the ComboBox ItemSource.
I know that in WPF it can be achieved as below:
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="#FFD2D2" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsValid}" Value="True">
<Setter Property="Background" Value="Green" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.ItemContainerStyle>
In UWP I tried using behaviors, but still, it's not working.
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="Background" Value="Transparent" />
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding IsValid}" Value="True">
<core:ChangePropertyAction PropertyName="Background" Value="{ThemeResource MyBorderBrush}" />
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Style>
</ComboBox.ItemContainerStyle>
I also tried to use VSM, but am not sure how to apply the conditional value.
<Style TargetType="ComboBoxItem">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Grid x:Name="LayoutRoot" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
// What should go here?
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
EDIT:
I would prefer a solution setting the background of ComboBoxItem itself, instead of creating separate Grid/Border and then using Converters for the background.