我有一个属性'AllShobeh'
public struct listViewShobehItem
{
string _code;
string _name;
string _tell;
string _address;
List<string> _atms;
public string Code
{
get
{
return _code;
}
set
{
_code = value;
}
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
public string Tell
{
get
{
return _tell;
}
set
{
_tell = value;
}
}
public string Address
{
get
{
return _address;
}
set
{
_address = value;
}
}
public List<string> Atms
{
get
{
return _atms;
}
set
{
_atms = value;
}
}
}
ObservableCollection<listViewShobehItem> _AllShobeh = new ObservableCollection<listViewShobehItem>();
public ObservableCollection<listViewShobehItem> AllShobeh
{
get { return _AllShobeh; }
set
{
_AllShobeh = new ObservableCollection<listViewShobehItem>(value);
OnPropertyChanged("AllShobeh");
}
}
构造函数中的我的代码:
AllShobeh = new ObservableCollection<listViewShobehItem>(from a in STATICS.db.shobehs
select new listViewShobehItem() {Code = a.code,Name=a.name,Tell=a.tell,Address=a.address,Atms=(from at in STATICS.db.atms
where at.shobehCode==a.code
select at.code + " - " + at.name).ToList()});
listviewShobeh.DataContext = this;
this.DataContext = this;
listviewShobeh.ItemsSource = AllShobeh;
我希望在列表视图中显示AllShobeh
并在列表框中的listView的最后一列显示Atms
...
这是我的Xaml代码:
<ListView Name="listviewShobeh" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Margin="5" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn x:Name="colCode" Header="code" DisplayMemberBinding="{Binding Path=Code}"/>
<GridViewColumn Header="name" DisplayMemberBinding="{Binding Path=Name}"/>
<GridViewColumn Header="tell" DisplayMemberBinding="{Binding Path=Tell}"/>
<GridViewColumn Header="address" DisplayMemberBinding="{Binding Path=Address}"/>
<GridViewColumn Header="atms" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Expander>
<ListBox ItemsSource="{Binding ElementName=listviewShobeh,Path=Atms}" DisplayMemberPath="{Binding Path=.}"/>
</Expander>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
我无法将Allshobeh.Atms绑定到listBox Atms列......
答案 0 :(得分:0)
从绑定中删除ElementName和DisplayMemberPath。
<DataTemplate>
<Expander>
<ListBox ItemsSource="{Binding Path=Atms}" />
</Expander>
</DataTemplate>
另外,更重要的是,您对DataContext和ViewModel类感到困惑,如果您需要关于这一点的具体帮助,请告诉我。