You can also use the converter:
(Sorry, I did not fully read your question)
Converters
using System; using System.Windows; using System.Windows.Data; using System.Globalization; namespace WPFSandbox { public class ComboBoxItemCountToEnabledConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null && value.GetType() == typeof(Int32)) { if ((int)value > 1) return true; } return false; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class ComboBoxItemCountToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null && value.GetType() == typeof(Int32)) { if ((int)value > 1) return Visibility.Visible; } return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }
Xaml
<Window ... ... xmlns:converters="clr-namespace:WPFSandbox"> <Window.Resources> <converters:ComboBoxItemCountToVisibilityConverter x:Key="ComboBoxItemCountToVisibilityConverter"/> <converters:ComboBoxItemCountToEnabledConverter x:Key="ComboBoxItemCountToEnabledConverter"/> </Window.Resources> <StackPanel> <ComboBox ItemsSource="{Binding C}" IsEnabled="{Binding Path=C.Count, Converter={StaticResource ComboBoxItemCountToEnabledConverter}}"/> <ToggleButton Visibility="{Binding Path=C.Count, Converter={StaticResource ComboBoxItemCountToVisibilityConverter}}"/> </StackPanel>
MyKuLLSKI
source share