My convert function not execute every time
My convert function not execute every time. following is my convert function.While load application that time it execute I want execute whenever I click on combo box.
Following is my code
<ComboBox x:Name="cbFlashes" Grid.Row="4" VerticalAlignment="Center" Grid.Column="1" Margin="5" ItemsSource="{Binding Flashes}" SelectedValue="{Binding SelectedFlash}" SelectedValuePath="Key" SelectedIndex="0" DisplayMemberPath="Value" IsEnabled="{Binding IsWorking, Converter={StaticResource NotBoolToBoolConverter}}" SelectionChanged="cbFlashes_SelectionChanged">
<!--Resource for Combobox to -->
<ComboBox.Resources>
<rd:ComboboxDisableConverter x:Key="itemDisableconverter"/>
</ComboBox.Resources>
<!--ItemContainer Style for disabling Combobox Item -->
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Content, RelativeSource={RelativeSource Self},
Converter={StaticResource itemDisableconverter}}" Value="true">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
Convert function
class ComboboxDisableConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string Sel = FirmwareUpdateViewModel.selectedFlash.ToString();
string result="";
if (value == null)
return value;
result = value.ToString();
int indexOf_ = 0;
if (result.Contains(","))
{
indexOf_ = result.IndexOf(',');
}
result = result.Remove(indexOf_);
result = result.Remove(0, 1);
// You can add your custom logic here to disable combobox item
if (Sel == "Doku1")
{
if (result == "Doku1")
{
return false;
}
else if (result == "Doku2")
{
return false;
}
else
{
return true;
}
}
else
{
return true;
}
return true;
}
}