WPF以编程方式在listview中创建checkboxcolumn

时间:2016-05-06 10:59:26

标签: wpf listview gridview

大家好)我有下一个问题 - 我应该在listview中创建一些复选框列。但它不起作用,它显示为真或假。

        private void CreateDataGridColumns()
    {
        var gridView = new GridView();
        PlanningDataGrid.View = gridView;
        gridView.Columns.Add(new GridViewColumn() {Header = "Тип мероприятия", DisplayMemberBinding = new Binding("Key")}); // Создаем первый столбец
        var eventTypeList = GetEventTypesList();
        foreach (string eventType in eventTypeList)
        {
            gridView.Columns.Add(new GridViewColumn() {Header = eventType, DisplayMemberBinding = new Binding("Value[" + eventType + "]"), CellTemplate = GenerateCellTemplate()});
        }
    }

    private DataTemplate GenerateCellTemplate()
    {
        var template = new DataTemplate();
        FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CheckBox));
        factory.SetBinding(CheckBox.IsCheckedProperty, new Binding());
        template.VisualTree = factory;
        return template;
    }

0 个答案:

没有答案