I have a combobox in a datagrid template. I have an event trigger on this that calls a command. I have confirmed that the command is calling my function. When my function returns false, I want to set the background color of the combo box to yellow. It if returns true, I want it to remain white.
The problem appears to be in the following section:
"Path=DataContext.ApplicationProfilesCollection[].ValidEnvironment"
In the output window I get:
"System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''ObservableCollection`1' (HashCode=44314665)'. BindingExpression:Path=DataContext.ApplicationProfilesCollection[].ValidEnvironment; DataItem='ProfilesUserControl' (Name=''); target element is 'ComboBox' (Name=''); target property is 'NoTarget' (type 'Object')"
Currently there are 3 items in the collection. Do you know how I get WFP to recognize each one? Does anything go in the "[ ]" in the XAML? Also - I must adhere to the MVVM pattern.
Please see XAML below. Thanks for your time,
<DataTemplate DataType="models:ApplicationProfile">
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type UserControl}},
Path=DataContext.DsnCollection}"
Validation.ErrorTemplate="{StaticResource ValidationTemplate}"
SelectedItem="{Binding DataSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ValidateDataSourceCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ApplicationProfilesCollection[].ValidEnvironment}" Value="false">
<Setter Property="ComboBox.Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
ValidEnvironment
is supposed to a publicbool
property of an item in theItemsSource
collection (DsnCollection
) that you set totrue
/false
for each item (Dsn
or whatever you call it) in the collection.You can then bind to it like this:
You can't bind a
DataTrigger
to a command because a command doesn't return anything.