You must Sign In to post a response.
  • Category: WPF

    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;
    }
    }
  • #768694
    Hi,

    Which function or event you are calling this?
    You are mentioning that you are calling at the page load. In that case it will work only once at the time of page load.
    If you want to make it work as everytime when you choose the Dropdown list then write those enter coding in the Combobox_Change event. Then only your functionality will get picked each time when the Combobox is selected or clicked.

    Thanks,
    Mani

  • #768702
    How can I call this in Combobox_Change event please suggest me
    I tried following code but did not get success.
    foreach (KeyValuePair<ProgramFlash, string> kvp in FirmwareUpdateViewModel.Flashes)
    {
    bool Res = Convert.ToBoolean(new ComboboxDisableConverter().Convert(kvp.Value.ToString(), null, "true", null));
    }

    can you give me your contact no so I can discuss with you.


Sign In to post your comments