Search code examples
silverlightxamltriggersexpression-blend

Conditional ChangePropertyAction Trigger for Combo Box


What I'm trying to do is set a condition visibility trigger (Silverlight) based on the choice made of a Telerik ComboBox. How do I tell it to look for if a value exists, then set the visibility on another control? The idea is, a different control isn't even visible until something is selected in the previous combobox.

So something like;

<i:Interaction.Triggers>
    <ei:DataTrigger Value="{x:Null}" Binding="{Binding Text,ElementName=FirstComboBox}">
       <ei:ChangePropertyAction TargetName="SecondComboBox" PropertyName="Visibility" Value="Collapsed"/>
    </ei:DataTrigger>
    <ei:DataTrigger Value="{A_VALUE_EXISTS_AS_CHOSEN_FROM_COMBO}" Binding="{Binding Text,ElementName=FirstComboBox}">
       <ei:ChangePropertyAction TargetName="SecondComboBox" PropertyName="Visibility" Value="Visible"/>
    </ei:DataTrigger>
</i:Interaction.Triggers>

I know I can go see if it's Null and no value exists, but once a choice is made from the combobox, regardless of what was chosen, how can I tell it if a value exists, fire off the Visible trigger?

So even simpler, If ComboBox1 has a value chose, ComboBox2 becomes visible? Thanks for sparing the time and brain power!


Solution

  • [ValueConversion(typeof(string), typeof(Visibility))]
    public class AuditVisabilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string input = (string)value;
            if (string.isNullOrEmpty(input)) return Visibility.Visible;
            else return Visibility.Collapsed;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return string.empty;
        }
    }