Link to a Silverlight list with the result of another combobox

I want to do something like this:

<combobox x:Name="cboCustomers" ItemsSource="{Binding Path=Data.Customers}"/>
<combobox x:Name="cboInvoices"ItemsSource="{cboCustomers.SelectedItem.Invoices}"/>

Does anyone know a way to do something like this in Silverlight 3? I am sure there is some information about this there, but I was not lucky with Google to formulate the question.

+3
source share
2 answers

You need to specify ElementNamein the second binding:

<combobox x:Name="cboCustomers" ItemsSource="{Binding Data.Customers}"/>
<combobox x:Name="cboInvoices"ItemsSource="{Binding SelectedItem.Invoices, ElementName=cboCustomers}"/>

If you also want the second combobox to be disabled until a property is selected in the first combo box, you can bind the property IsEnabledto the second combobox to the property of the SelectedItemfirst combo box through the converter.

Add this class to your project:

public class NullToBooleanConverter : IValueConverter {

  public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) {
    if (targetType == typeof(Boolean))
      return value != null;
    throw new NotSupportedException("Value converter can only convert to Boolean type.");
  }

  public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture) {
    throw new NotSupportedException("Value converter cannot convert back.");
  }

}

(local - ):

<UserControl.Resources>
  <local:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
</UserControl.Resources>

:

IsEnabled="{Binding SelectedItem, ElementName=cboCustomers, Converter={StaticResource NullToBooleanConverter}}"
+4

Source: https://habr.com/ru/post/1719055/


All Articles