:) I have one DataGrid. In Column2 there is "ComboBox1", in Column3 there is "ComboBox2". I would like to set IsEnabled to false on "ComboBox2" as long as "ComboBox1" has SelectedIndex=0. For each row seperately.
This works perfectly outside the Datagrid with two ComboBoxes (with the help of Style and DataTrigger). However, inside the Datagrid, within Column3 I cannot "see" "ComboBox1" ("Cannot find source for binding...").
It's basically a namescope issue. However, referring to a Combobox within a DataGrid by name seems to be wrong in the first place. So: any ideas how to accomplish this?
Thank you very much in advance!
<Window.Resources>
<CollectionViewSource x:Key="Source1" Source="{Binding List1}" />
<CollectionViewSource x:Key="Source2" Source="{Binding List2}" />
</Window.Resources>
<DataGrid x:Name="ModelControl" AutoGenerateColumns="False" ItemsSource="{Binding List3}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding MyName}" Header="Modellname" />
<DataGridTemplateColumn Header="Header 1">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="ComboBox1" DisplayMemberPath="MyName" SelectedIndex="0">
<ComboBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource Source2}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Header 2">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="ComboBox2" DisplayMemberPath="MyName">
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="IsEnabled" Value="True" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex,ElementName=ComboBox1}" Value="0">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource Source1}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Please don't mind the CompositeCollection.