我有2个ListBox(“类型”和“产品”) “类型”从数据库中获取所有数据。我想列出“产品”,它是在“类型”列表框中选择的类型。
我想在WPF中这样做。 你能帮助我吗? 感谢您的关注
答案 0 :(得分:2)
我认为类型与产品有些相关。然后你可以做到以下几点。 (当然,你必须设置正确的DataContext)。
public class Types
{
public List<Product> MyProducts {get; set;}
}
xaml.cs或mvvm
{
public List<Types> MyTypesCollection {get; set;}
}
XAML
<ListBox x:Name=lstTypes ItemSource="{Binding MyTypesCollection}" />
<ListBox ItemsSource="{Binding ElementName=lstTypes, Path=SelectedItem.MyProducts}"/>