Herve NDILIMABAKA

Herve NDILIMABAKA

  • NA
  • 75
  • 7.7k

How to disable a ComboBox item in a DataTemplate in wpf c#

Dec 30 2017 9:10 PM
Hi everybody
 
I have a DataGrid control for which one of the columns consists in ComboBox controls defined in a DataTemplate (refer to the xaml snippet below).
 
The ComboBox controls are populated through data binding and everything works fine.
 
My problem: I would like to disable (from code behind) the selected ComboBox control item as long as the treatment associated to that selection is not complete.
 
Any idea, comment, suggestion?
 
Here is the xaml snippet:
 
<DataGrid Name="onGoingActionsGrid" AutoGenerateColumns="False" Background="Transparent" BorderBrush="Transparent"
CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserResizeColumns="False">
<datagrid.columns>
<DataGridTextColumn Header="Actions" Width="235" Binding="{Binding Name}"/>
<DataGridTemplateColumn Header="State" IsReadOnly="True" Width="40">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<DataGridTemplateColumn Header="Control" Width="50">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<ComboBox x:Name="ControlActionComboBox"
ItemsSource="{Binding CollectionOfPictograms, Mode=TwoWay}"
SelectionChanged="controlAction_SelectionChanged"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
SelectedValuePath="Content">
<combobox.itemcontainerstyle>
<Setter Property="Padding" Value="4.3"/>
<Setter Property="BorderBrush" Value="LightGray"/>
<Setter Property="BorderThickness" Value="1"/>
<combobox.itemtemplate>
<datatemplate>
<dockpanel>

Answers (2)