Пример #1
0
        /// <summary>
        /// 创建用于构建设置DataGrid的列的数据源
        /// </summary>
        /// <param name="element">目标源,Page、Window等</param>
        /// <returns></returns>
        public static List <ColumnItem> BuilderDataGridSettingColumn(this FrameworkElement element)
        {
            if (!(typeof(Page).IsAssignableFrom(element.GetType()) || typeof(Window).IsAssignableFrom(element.GetType())))
            {
                throw new ArgumentNullException("当前窗体必须派生自Page、Window");
            }
            //创建用于构建设置DataGrid的列的数据源
            List <ColumnItem> columns = new List <ColumnItem>();
            //二级
            var col1 = new ColumnItem("列名");

            col1.Columns.Add(new ColumnItem("默认列名", "Name", "", "", HorizontalAlignment.Right, 120));
            col1.Columns.Add(new ColumnItem("自定义列名", "ExtendName", "", "", HorizontalAlignment.Stretch, 120, ColumnType.TextBox));
            columns.Add(col1);
            //一级
            columns.Add(new ColumnItem("列宽", "Width", "", "", HorizontalAlignment.Stretch, 80, ColumnType.TextBox));
            //绑定一个ComboBox数据源
            //位置比较特殊,此处绑定的是另外一个数据源,设置不同的数据源需要设置不同的绑定参数
            var horizontalAlignment = new ColumnItem("位置", "Alignment", "horizontalAlignmentValueConverter", "", HorizontalAlignment.Stretch, 80, ColumnType.ComboBox);

            horizontalAlignment.SetColumnComboBox(new ColumnComboBox(
                                                      "ComboBoxDatas,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}", //
                                                      "",
                                                      "",
                                                      "")); //SelectItemA,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}
            columns.Add(horizontalAlignment);
            columns.Add(new ColumnItem("显示", "Visibility", "visibilityValueConverter", "", HorizontalAlignment.Center, 80, ColumnType.CheckBox));
            return(columns);
        }
Пример #2
0
        private void OnLoadSetting(List <ColumnItem> settingDatas)
        {
            List <ColumnItem> columns = new List <ColumnItem>();
            //二级,经此类推,不限级
            var col1 = new ColumnItem("列名");

            col1.Columns.Add(new ColumnItem("默认列名", "Name", "", "", HorizontalAlignment.Right, 120));
            col1.Columns.Add(new ColumnItem("自定义列名", "ExtendName", "", "", HorizontalAlignment.Stretch, 120, ColumnType.TextBox));
            columns.Add(col1);
            //一级
            columns.Add(new ColumnItem("列宽", "Width", "", "", HorizontalAlignment.Stretch, 80, ColumnType.TextBox));
            var _ = new ColumnItem("位置", "Alignment", "horizontalAlignmentValueConverter", "", HorizontalAlignment.Stretch, 80, ColumnType.ComboBox);

            _.SetColumnComboBox(new ColumnComboBox("ComboBoxDatas,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}",
                                                   "", "Name", "Name")); //SelectItemA,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}
            columns.Add(_);

            columns.Add(new ColumnItem("显示", "Visibility", "visibilityValueConverter", "", HorizontalAlignment.Center, 80, ColumnType.CheckBox));

            this.settingList.AddBindingPathTemplateColumn(columns); //添加列集合
            this.GetSettingDatas(ref mSettingDatas, settingDatas);
            this.settingList.ItemsSource = this.mSettingDatas;
        }