packages/MaterialDesignThemes.2.5.0.1205/src/net45/MaterialDataGridComboBoxColumn.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace MaterialDesignThemes.Wpf
{
    public class MaterialDataGridComboBoxColumn : DataGridComboBoxColumn //DataGridBoundColumn
    {
        static MaterialDataGridComboBoxColumn()
        {            
            ElementStyleProperty.OverrideMetadata(typeof(MaterialDataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultElementStyle));
            EditingElementStyleProperty.OverrideMetadata(typeof(MaterialDataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultEditingElementStyle));
        }

        public Binding ItemsSourceBinding { get; set; }

        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            var comboBox = base.GenerateElement(cell, cell);

            if (ItemsSourceBinding != null)
                comboBox.SetBinding(ItemsControl.ItemsSourceProperty, ItemsSourceBinding);
            ApplyStyle(false, false, comboBox);                       

            return comboBox;
        }

        protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
        {
            var comboBox = (ComboBox)base.GenerateElement(cell, cell);

            if (ItemsSourceBinding != null)
                comboBox.SetBinding(ItemsControl.ItemsSourceProperty, ItemsSourceBinding);            
            ApplyStyle(true, false, comboBox);            

            return comboBox;
        }

        public static new Style DefaultElementStyle
        {
            get
            {
                var comboBox = new ComboBox();

                var brushKey = new ComponentResourceKey(typeof(ComboBox), "MaterialDataGridComboBoxColumnStyle");
                var style = (Style)comboBox.TryFindResource(brushKey);

                return style;
            }
        }

        public static new Style DefaultEditingElementStyle
        {
            get
            {
                var comboBox = new ComboBox();

                var brushKey = new ComponentResourceKey(typeof(ComboBox), "MaterialDataGridComboBoxColumnEditingStyle");
                var style = (Style)comboBox.TryFindResource(brushKey);

后面还有 44 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。