Click here to Skip to main content
15,887,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
private CarType _inspectMethod;
    
    public CarType InspectMethod
    {
    
            get
            {
                return _inspectMethod;
            }
            set
            {
     
                _inspectMethod= value;
                RaisePropertyChanged();
                
             if(InspectMethod!= null)
                {                    
                    InspectTypelist = InspectMethod.InspectType;
                }
    }   

    <Label Grid.Row="0" Grid.Column="0" Content="value:" />
   <ComboBox Width="Auto" Grid.Row="4" Grid.Column="1" SelectedValuePath="Id" 
    DisplayMemberPath="Name" SelectedItem="{ Binding ElementName=LayoutRoot, 
    Path=DataContext.InspectMethod}" ItemsSource="{ Binding 
    ElementName=LayoutRoot, Path=DataContext.InspectMethodList}"/>


What I have tried:

C#
bool _isEnable;
 public bool IsEnable

        {
            get
            {
                return this._isEnable;
            }

            set
            {
                this._isEnable = value;
            }
        }

 <ComboBox Width="Auto" Grid.Row="4" Grid.Column="1" IsEnable="Binding something here" SelectedValuePath="Id" 
    DisplayMemberPath="Name" SelectedItem="{ Binding ElementName=LayoutRoot, 
    Path=DataContext.InspectMethod}" ItemsSource="{ Binding 
    ElementName=LayoutRoot, Path=DataContext.InspectMethodList}"/>
Posted
Updated 7-Nov-18 21:02pm

1 solution

What do you mean by combobox value. do you mean enable-diable combo box has list of items or not. If this is the case, you can use following code

C#
public class ComboBoxEnableConverter : IValueConverter
   {
       public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
       {
           bool hasItem = (bool)value;
           if (hasItem)
               return true;
           return false;
       }
       public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
       {
           throw new NotImplementedException();
       }
   }


Then Add to Resource and bind to Enable property as given below

XML
<UserControl.Resources>
        <common:ComboBoxEnableConverter x:Key="EnableConverter"/>
</UserControl.Resources>

<ComboBox x:Name="cmboBox" IsEnabled="{Binding ElementName=cmboBox, Path=HasItems, Converter={StaticResource EnableConverter}}"/>



1. Define converter if you want to convert source value into target e.g items count to boolean (IsEnable on accepts boolean)
2. Bind IsEnable property to your requirement. In this example I want to check if combo box has some items in item source. if yes, Converter will return true, else false
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900