I've just discovered the power of the datatriggers and now Im trying to change the background of each items in my listbox according to a boolean property in the type I've bound.
This is the Style setting:
<Style x:Key="InvalidSettingStyle" TargetType="StackPanel">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ValidSetting}" Value="false">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
This is the Datatemplate that I use:
<DataTemplate x:Key="ComboBoxTemplate" DataType="self:ListBoxComboBoxElement">
<StackPanel Orientation="Vertical" Style="{StaticResource InvalidSettingStyle}">
<CheckBox IsChecked="{Binding IsActive}" Content="{Binding Content}"/>
<ComboBox ItemsSource="{Binding Path= FirstComboBox.Items}"
SelectedItem="{Binding Path=FirstComboBox.SelectedRevitElement}"
SelectionChanged="ComboBox_SelectionChanged"/>
</StackPanel>
</DataTemplate>
I accidently ran it with the DataTrigger settings you can see above without setting the ValidSetting property to true before loading the form and they all turned out red. So there is some kind of connection, but I cant change the background while loaded.
All my other bindings work like a charm. The items are in a observablecollection bound to the Itemsource property of the Listbox.
Any ideas?
DependencyObject
nor implementsINotifyPropertyChanged
. I.e. it has no way to report changes in theValidSetting
property value. But it could be something completely different instead. Please improve the code example. - Peter DunihoINotifyPropertyChanged
interface in yourListBoxComboBoxElement
class. - SheridanListBox
bound to an observable collection. Is the data template that you have posted the one used for the items in the list box? In other words, each item in your list box appears as a check box with a combo box next to it? - Steven Rands