我似乎无法让它工作。任何人有任何想法为什么?
这是标记:
<ListView Width="210" Height="83" Margin="0 0 5 0" Name="FiltersListView">
<ListView.View>
<GridView>
<GridViewColumn Header="Column" Width="Auto" DisplayMemberBinding="{Binding FilterColumn}"></GridViewColumn>
<GridViewColumn Header="Rule" Width="Auto" DisplayMemberBinding="{Binding FilterRule}"></GridViewColumn>
<GridViewColumn Header="String" Width="Auto" DisplayMemberBinding="{Binding FilterString}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
这是窗口初始化程序:
public SelectionWindow()
{
InitializeComponent();
rows = new List<Row>();
// Create a new binding object and set the binding of this list view to it.
Binding myBinding = new Binding();
myBinding.Source = rows;
FiltersListView.SetBinding(ItemsControl.ItemsSourceProperty, myBinding);
}
这是我的行对象和类:
List<Row> rows;
public class Row
{
public string FilterColumn;
public string FilterRule;
public string FilterString;
}
但是当我点击这个按钮时,我没有看到它被添加到列表中:
private void AddButtonClick(object sender, RoutedEventArgs e)
{
Console.WriteLine("Adding row.");
rows.Add(new Row { FilterColumn = "1", FilterRule = "2", FilterString = "3" });
Console.WriteLine("Row added.");
}