protected override void ApplyProperties(CellDefinition cd, DataGrid owner, CellRef cell, PropertyDefinition pd, object item)
 {
     base.ApplyProperties(cd, owner, cell, pd, item);
     cd.IsEnabledBindingSource = this.isItemEnabledSource;
     cd.IsEnabledBindingParameter = "yes";
     cd.IsEnabledBindingPath = owner.Operator.GetBindingPath(owner, cell);
 }
Exemplo n.º 2
0
 public override FrameworkElement CreateEditControl(PropertyDefinition d, int index)
 {
     if (d.PropertyName.Contains("Path"))
     {
         return CreateFilePicker(d, index);
     }
     return base.CreateEditControl(d, index);
 }
Exemplo n.º 3
0
 private FrameworkElement CreateFilePicker(PropertyDefinition property, int index)
 {
     var c = new FilePicker
     {
         Filter = "Image Files (*.jpg, *.png)|*.jpg;*.png",
         UseOpenDialog = true,
     };
     c.SetBinding(FilePicker.FilePathProperty, property.CreateBinding(index));
     return c;
 }
        /// <summary>
        /// Creates the cell definition object.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="cell">The cell.</param>
        /// <param name="pd">The property definition.</param>
        /// <param name="item">The item.</param>
        /// <returns>A cell definition.</returns>
        protected virtual CellDefinition CreateCellDefinitionOverride(DataGrid owner, CellRef cell, PropertyDefinition pd, object item)
        {
            var propertyType = owner.Operator.GetPropertyType(pd, cell, item);

            var tcd = pd as TemplateColumnDefinition;
            if (tcd != null)
            {
                return new TemplateCellDefinition
                {
                    DisplayTemplate = tcd.CellTemplate,
                    EditTemplate = tcd.CellEditingTemplate
                };
            }

            if (propertyType.Is(typeof(bool)))
            {
                return new CheckCellDefinition();
            }

            if (propertyType.Is(typeof(Color)))
            {
                return new ColorCellDefinition();
            }

            if (propertyType.Is(typeof(Enum)))
            {
                var enumType = Nullable.GetUnderlyingType(propertyType) ?? propertyType;
                var values = Enum.GetValues(enumType).Cast<object>().ToList();
                if (Nullable.GetUnderlyingType(propertyType) != null)
                {
                    values.Insert(0, null);
                }

                return new SelectCellDefinition
                {
                    ItemsSource = values
                };
            }

            if (pd.ItemsSourceProperty != null || pd.ItemsSource != null)
            {
                return new SelectCellDefinition
                {
                    ItemsSource = pd.ItemsSource,
                    ItemsSourceProperty = pd.ItemsSourceProperty
                };
            }

            return new TextCellDefinition();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a display control.
        /// </summary>
        /// <param name="d">
        /// The definition.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// The display control.
        /// </returns>
        public virtual FrameworkElement CreateDisplayControl(PropertyDefinition d, int index)
        {
            var propertyType = d.PropertyType;
            if (propertyType.Is(typeof(bool)))
            {
                return this.CreateCheckBoxControl(d, index);
            }

            if (propertyType.Is(typeof(Color)))
            {
                return this.CreateColorPreviewControl(d, index);
            }

            return this.CreateTextBlockControl(d, index);
        }
        /// <summary>
        /// Creates the display control with data binding.
        /// </summary>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>
        /// The control.
        /// </returns>
        public virtual FrameworkElement CreateDisplayControl(PropertyDefinition propertyDefinition, string bindingPath)
        {
            var propertyType = propertyDefinition.PropertyType;
            if (propertyType.Is(typeof(bool)))
            {
                return this.CreateCheckBoxControl(propertyDefinition, bindingPath);
            }

            if (propertyType.Is(typeof(Color)))
            {
                return this.CreateColorPreviewControl(propertyDefinition, bindingPath);
            }

            return this.CreateTextBlockControl(propertyDefinition, bindingPath);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates an edit control.
        /// </summary>
        /// <param name="d">
        /// The definition.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// The edit control.
        /// </returns>
        public virtual FrameworkElement CreateEditControl(PropertyDefinition d, int index)
        {
            var propertyType = d.PropertyType;
            if (d.ItemsSourceProperty != null || d.ItemsSource != null)
            {
                return this.CreateComboBox(d, index);
            }

            if (propertyType == typeof(bool))
            {
                return null;
            }

            if (propertyType != null && propertyType.Is(typeof(Color)))
            {
                return this.CreateColorPickerControl(d, index);
            }

            return this.CreateTextBox(d, index);
        }
        /// <summary>
        /// Creates the edit control with data binding.
        /// </summary>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>
        /// The control.
        /// </returns>
        public virtual FrameworkElement CreateEditControl(PropertyDefinition propertyDefinition, string bindingPath)
        {
            var propertyType = propertyDefinition.PropertyType;
            if (propertyDefinition.ItemsSourceProperty != null || propertyDefinition.ItemsSource != null)
            {
                return this.CreateComboBox(propertyDefinition, bindingPath);
            }

            if (propertyType == typeof(bool))
            {
                return null;
            }

            if (propertyType != null && propertyType.Is(typeof(Color)))
            {
                return this.CreateColorPickerControl(propertyDefinition, bindingPath);
            }

            return this.CreateTextBox(propertyDefinition, bindingPath);
        }
        /// <summary>
        /// Applies the properties to the specified cell definition.
        /// </summary>
        /// <param name="cd">The cell definition.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="cell">The cell.</param>
        /// <param name="pd">The row/column definition.</param>
        /// <param name="item">The current value of the cell.</param>
        protected virtual void ApplyProperties(CellDefinition cd, DataGrid owner, CellRef cell, PropertyDefinition pd, object item)
        {
            cd.HorizontalAlignment = pd.HorizontalAlignment;
            cd.BindingPath = pd.PropertyName ?? owner.Operator.GetBindingPath(owner, cell);
            cd.IsReadOnly = pd.IsReadOnly;
            cd.FormatString = pd.FormatString;
            if (pd.Converter != null)
            {
                cd.Converter = pd.Converter;
            }

            cd.ConverterParameter = pd.ConverterParameter;
            cd.ConverterCulture = pd.ConverterCulture;

            cd.IsEnabledBindingParameter = pd.IsEnabledByValue;
            cd.IsEnabledBindingPath = pd.IsEnabledByProperty;
            cd.BackgroundBindingPath = pd.BackgroundProperty;

            if (pd.Background != null)
            {
                cd.BackgroundBindingSource = pd.Background;
                cd.BackgroundBindingPath = string.Empty;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a text block control.
        /// </summary>
        /// <param name="d">
        /// The definition.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// A TextBlock.
        /// </returns>
        protected virtual FrameworkElement CreateTextBlockControl(PropertyDefinition d, int index)
        {
            var tb = new TextBlock
                {
                    HorizontalAlignment = d.HorizontalAlignment,
                    VerticalAlignment = VerticalAlignment.Center,
                    Padding = new Thickness(4, 0, 4, 0)
                };

            tb.SetBinding(TextBlock.TextProperty, d.CreateOneWayBinding(index));
            return tb;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a combo box.
        /// </summary>
        /// <param name="d">
        /// The definition.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// A ComboBox.
        /// </returns>
        protected virtual FrameworkElement CreateComboBox(PropertyDefinition d, int index)
        {
            var c = new ComboBox { IsEditable = d.IsEditable, Focusable = false, Margin = new Thickness(0, 0, -1, -1) };
            if (d.ItemsSource != null)
            {
                c.ItemsSource = d.ItemsSource;
            }
            else
            {
                if (d.ItemsSourceProperty != null)
                {
                    var itemsSourceBinding = new Binding(d.ItemsSourceProperty);
                    c.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);
                }
            }

            c.DropDownClosed += (s, e) => FocusParentItemsGrid(c);
            var binding = d.CreateBinding(index);
            binding.NotifyOnSourceUpdated = true;
            c.SetBinding(d.IsEditable ? ComboBox.TextProperty : Selector.SelectedValueProperty, binding);

            return c;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a color preview control.
        /// </summary>
        /// <param name="d">
        /// The definition.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// A preview control.
        /// </returns>
        protected virtual FrameworkElement CreateColorPreviewControl(PropertyDefinition d, int index)
        {
            var c = new Rectangle
                {
                    Stroke = Brushes.Black,
                    StrokeThickness = 1,
                    Width = 12,
                    Height = 12,
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center
                };

            var binding = d.CreateBinding(index);
            binding.Converter = new ColorToBrushConverter();
            c.SetBinding(Shape.FillProperty, binding);
            return c;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a color picker control.
 /// </summary>
 /// <param name="d">
 /// The definition.
 /// </param>
 /// <param name="index">
 /// The index.
 /// </param>
 /// <returns>
 /// A color picker.
 /// </returns>
 protected virtual FrameworkElement CreateColorPickerControl(PropertyDefinition d, int index)
 {
     var c = new ColorPicker2
         {
             VerticalAlignment = VerticalAlignment.Center,
             HorizontalAlignment = HorizontalAlignment.Stretch,
             Focusable = false
         };
     c.SetBinding(ColorPicker2.SelectedColorProperty, d.CreateBinding(index));
     return c;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a check box control.
        /// </summary>
        /// <param name="d">
        /// The definition.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// A CheckBox.
        /// </returns>
        protected virtual FrameworkElement CreateCheckBoxControl(PropertyDefinition d, int index)
        {
            if (d.IsReadOnly)
            {
                var cm = new CheckMark
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                HorizontalAlignment = d.HorizontalAlignment
                            };
                cm.SetBinding(CheckMark.IsCheckedProperty, d.CreateBinding(index));
                return cm;
            }

            var c = new CheckBox
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = d.HorizontalAlignment,
                    IsEnabled = !d.IsReadOnly
                };
            c.SetBinding(ToggleButton.IsCheckedProperty, d.CreateBinding(index));
            return c;
        }
 protected override void ApplyProperties(CellDefinition cd, DataGrid owner, CellRef cell, PropertyDefinition pd, object item)
 {
     base.ApplyProperties(cd, owner, cell, pd, item);
     cd.BackgroundBindingSource = this.backgroundSource;
     cd.BackgroundBindingPath = owner.Operator.GetBindingPath(owner, cell);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a text block control with data binding.
        /// </summary>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>
        /// A TextBlock.
        /// </returns>
        protected virtual FrameworkElement CreateTextBlockControl(PropertyDefinition propertyDefinition, string bindingPath)
        {
            var tb = new TextBlock
            {
                HorizontalAlignment = propertyDefinition.HorizontalAlignment,
                VerticalAlignment = VerticalAlignment.Center,
                Padding = new Thickness(4, 0, 4, 0)
            };

            tb.SetBinding(TextBlock.TextProperty, propertyDefinition.CreateOneWayBinding(bindingPath));
            return tb;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Creates a check box control with data binding.
        /// </summary>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>
        /// A CheckBox.
        /// </returns>
        protected virtual FrameworkElement CreateCheckBoxControl(PropertyDefinition propertyDefinition, string bindingPath)
        {
            if (propertyDefinition.IsReadOnly)
            {
                var cm = new CheckMark
                             {
                                 VerticalAlignment = VerticalAlignment.Center,
                                 HorizontalAlignment = propertyDefinition.HorizontalAlignment
                             };
                cm.SetBinding(CheckMark.IsCheckedProperty, propertyDefinition.CreateBinding(bindingPath));
                return cm;
            }

            var c = new CheckBox
                        {
                            VerticalAlignment = VerticalAlignment.Center,
                            HorizontalAlignment = propertyDefinition.HorizontalAlignment,
                            IsEnabled = !propertyDefinition.IsReadOnly
                        };
            c.SetBinding(ToggleButton.IsCheckedProperty, propertyDefinition.CreateBinding(bindingPath));
            return c;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Creates edit control.
 /// </summary>
 /// <param name="cell">The cell reference.</param>
 /// <param name="pd">The <see cref="PropertyDefinition" />.</param>
 /// <returns>
 /// The edit control.
 /// </returns>
 public override FrameworkElement CreateEditControl(CellRef cell, PropertyDefinition pd)
 {
     return(this.ControlFactory.CreateEditControl(pd, pd.GetBindingPath(cell)));
 }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a text box with data binding.
        /// </summary>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>A TextBox.</returns>
        protected virtual FrameworkElement CreateTextBox(PropertyDefinition propertyDefinition, string bindingPath)
        {
            var tb = new TextBox
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                HorizontalContentAlignment = propertyDefinition.HorizontalAlignment,
                MaxLength = propertyDefinition.MaxLength,
                BorderThickness = new Thickness(0),
                Margin = new Thickness(1, 1, 0, 0)
            };

            tb.SetBinding(TextBox.TextProperty, propertyDefinition.CreateBinding(bindingPath));
            return tb;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Creates a text box.
        /// </summary>
        /// <param name="d">
        /// The definition.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// A TextBox.
        /// </returns>
        protected virtual FrameworkElement CreateTextBox(PropertyDefinition d, int index)
        {
            var tb = new TextBox
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    HorizontalContentAlignment = d.HorizontalAlignment,
                    MaxLength = d.MaxLength,
                    BorderThickness = new Thickness(0),
                    Margin = new Thickness(1, 1, 0, 0)
                };
            tb.SetBinding(TextBox.TextProperty, d.CreateBinding(index));

            return tb;
        }
Exemplo n.º 21
0
 /// <summary>
 /// Creates edit control.
 /// </summary>
 /// <param name="cell">The cell reference.</param>
 /// <param name="pd">The <see cref="PropertyDefinition" />.</param>
 /// <returns>
 /// The edit control.
 /// </returns>
 public override FrameworkElement CreateEditControl(CellRef cell, PropertyDefinition pd)
 {
     return this.ControlFactory.CreateEditControl(pd, pd.GetBindingPath(cell));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Creates edit control.
 /// </summary>
 /// <param name="cell">The cell reference.</param>
 /// <param name="pd">The <see cref="PropertyDefinition" />.</param>
 /// <returns>
 /// The edit control.
 /// </returns>
 public override FrameworkElement CreateEditControl(CellRef cell, PropertyDefinition pd)
 {
     var index = Owner.GetItemIndex(cell);
     return this.ControlFactory.CreateEditControl(pd, pd.GetBindingPath(index));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Creates a color picker control with data binding.
 /// </summary>
 /// <param name="propertyDefinition">The property definition.</param>
 /// <param name="bindingPath">The binding path.</param>
 /// <returns>
 /// A color picker.
 /// </returns>
 protected virtual FrameworkElement CreateColorPickerControl(PropertyDefinition propertyDefinition, string bindingPath)
 {
     var c = new ColorPicker
         {
             VerticalAlignment = VerticalAlignment.Center,
             HorizontalAlignment = HorizontalAlignment.Stretch,
             Focusable = false
         };
     c.SetBinding(ColorPicker.SelectedColorProperty, propertyDefinition.CreateBinding(bindingPath));
     return c;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Creates edit control.
 /// </summary>
 /// <param name="cell">The cell reference.</param>
 /// <param name="pd">The <see cref="PropertyDefinition" />.</param>
 /// <returns>
 /// The edit control.
 /// </returns>
 public abstract FrameworkElement CreateEditControl(CellRef cell, PropertyDefinition pd);
        /// <summary>
        /// Creates a combo box with data binding.
        /// </summary>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>
        /// A ComboBox.
        /// </returns>
        protected virtual FrameworkElement CreateComboBox(PropertyDefinition propertyDefinition, string bindingPath)
        {
            var c = new ComboBox { IsEditable = propertyDefinition.IsEditable, Focusable = false, Margin = new Thickness(0, 0, -1, -1) };
            if (propertyDefinition.ItemsSource != null)
            {
                c.ItemsSource = propertyDefinition.ItemsSource;
            }
            else
            {
                if (propertyDefinition.ItemsSourceProperty != null)
                {
                    var itemsSourceBinding = new Binding(propertyDefinition.ItemsSourceProperty);
                    c.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);
                }
            }

            c.DropDownClosed += (s, e) => FocusParentDataGrid(c);
            var binding = propertyDefinition.CreateBinding(bindingPath);
            binding.NotifyOnSourceUpdated = true;
            c.SetBinding(propertyDefinition.IsEditable ? ComboBox.TextProperty : Selector.SelectedValueProperty, binding);

            var selectedValuePathAttribute = propertyDefinition.Descriptor.Attributes.OfType<SelectedValuePathAttribute>().FirstOrDefault();
            if (selectedValuePathAttribute != null)
            {
                c.SelectedValuePath = selectedValuePathAttribute.Path;
            }
            
            return c;
        }