将silverlight combobox绑定到另一个combobox的结果
我想这样做:将silverlight combobox绑定到另一个combobox的结果,silverlight,data-binding,xaml,Silverlight,Data Binding,Xaml,我想这样做: <combobox x:Name="cboCustomers" ItemsSource="{Binding Path=Data.Customers}"/> <combobox x:Name="cboInvoices"ItemsSource="{cboCustomers.SelectedItem.Invoices}"/> 有人知道在Silverlight 3中这样做的方法吗?我肯定有一些关于这个问题的信息,但我在谷歌提出这个问题时运气不好。你会看到一个层
<combobox x:Name="cboCustomers" ItemsSource="{Binding Path=Data.Customers}"/>
<combobox x:Name="cboInvoices"ItemsSource="{cboCustomers.SelectedItem.Invoices}"/>
有人知道在Silverlight 3中这样做的方法吗?我肯定有一些关于这个问题的信息,但我在谷歌提出这个问题时运气不好。你会看到一个层叠的组合框
您需要在第二个绑定上指定
ElementName
:
<combobox x:Name="cboCustomers" ItemsSource="{Binding Data.Customers}"/>
<combobox x:Name="cboInvoices"ItemsSource="{Binding SelectedItem.Invoices, ElementName=cboCustomers}"/>
将此类的实例添加到用户控件的资源字典中(local
是转换器名称空间的名称空间标记):
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.");
}
}
<UserControl.Resources>
<local:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
</UserControl.Resources>
IsEnabled="{Binding SelectedItem, ElementName=cboCustomers, Converter={StaticResource NullToBooleanConverter}}"