如果我正确理解你,你可以设置你的ListBox的DataContext为一个类的实例(在我的例子中,我在代码中做:list.DataContext = myclass;),并且你想设置您的列表框的ItemSource添加到类中的列表(即Items)和组合框的itemssource到类中的另一个列表(即Values)中。这里是我的XAML,似乎工作:
<ListBox Name="list" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}"/>
<ComboBox ItemsSource=
"{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListBox}},
Path=DataContext.Values}"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和继承人是我绑定到类:
public class AClass
{
protected List<string> _Items;
public List<string> Items
{
get
{
if (_Items == null)
{
_Items = new List<string>();
}
return _Items;
}
}
protected List<string> _Values;
public List<string> Values
{
get
{
if (_Values == null)
{
_Values = new List<string>();
}
return _Values;
}
}
}
在代码中,我创建ACLASS的实例,添加项目和值,并设置实例添加到列表框的DataContext中。
需要查看所有的XAML来帮助您处理这个问题。 – Charlie 2009-07-27 19:19:15