gpt4 book ai didi

silverlight - 将 silverlight 组合框绑定(bind)到另一个组合框的结果

转载 作者:行者123 更新时间:2023-12-01 23:15:48 25 4
gpt4 key购买 nike

我想做这样的事情:

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

有人知道在 Silverlight 3 中执行类似操作的方法吗?我确信那里有一些关于它的信息,但我在 Google 提出这个问题时运气不好。

最佳答案

您需要在第二个绑定(bind)上指定 ElementName:

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

如果您还希望在第一个组合框中选择某些内容之前禁用第二个组合框,您可以将第二个组合框的 IsEnabled 属性绑定(bind)到 SelectedItem 属性通过转换器的第一个组合框。

将此类添加到您的项目中:

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}}"

关于silverlight - 将 silverlight 组合框绑定(bind)到另一个组合框的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1506810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com