把我的头伸出来。我无法在我的listview
内将我的combobox
绑定到后面代码中的列表。Combobox绑定ListView中的WPF
另外,combobox
甚至没有出现在列中..
想要一个在listview
combobox
显示数字0-24。
XAML:
<ListView Grid.Row="0" Margin="0,0,0,0" Height="250" Width="540" SelectionMode="Single" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" x:Name="TasksList">
<ListView.View>
<GridView>
<GridViewColumn Header ="Day 1" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=ComboBox1}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
和代码背后:
public partial class TaskHoursRemaining : Page {
List<int> hourOfDay = new List<int>();
public TaskHoursRemaining() {
InitializeComponent();
LoadData();
DataContext = this;
}
private void LoadData() {
for (int i = 0; i < 25; i++) {
hourOfDay.Add(i);
}
this.ComboBox1.ItemsSource= hourOfDay;
}
}
但ComboBox1
不会在当前的背景下存在。
你在做什么错在这里是,控制是在列表视图的DataTemplate ,所以你必须绑定ListView和必需的集合 –