0

我似乎无法让它工作。任何人有任何想法为什么?

这是标记:

<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.");
        }
4

1 回答 1

1

这是因为List<int>没有实现INotifyCollectionChanged,所以控件不知道列表实际上已经更新。

尝试制作rows一个ObservableColelction<Row>.


编辑:正如 OP 提到的,另一个问题(空行)是由于在Row.

于 2013-05-28T19:56:39.200 回答