0

I have a user control with a datagrid called IGrid. I want to add GridViewColumnCollection poperty for it.

public class DataGridNumericColumn : DataGridTextColumn
{
    protected override object PrepareCellForEdit(System.Windows.FrameworkElement editingElement, System.Windows.RoutedEventArgs editingEventArgs)
    {
        TextBox edit = editingElement as TextBox;
        edit.PreviewTextInput += OnPreviewTextInput;
        return base.PrepareCellForEdit(editingElement, editingEventArgs);
    }
    void OnPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
    {
        try
        {
            Convert.ToInt32(e.Text);
        }
        catch
        {
            e.Handled = true;
        }
    }
}

From Google i got a piece of code `

private Collection<DataGridColumn> field = new Collection<DataGridColumn>();
[Category("Data")]
[Description("Column Creation")]                     
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Collection<DataGridColumn> Columns
{
    get { return field; }
}

Here I can get GridViewColumnCollection in visual tree , My question is how to add a new type (DataGridNumericColumn )in the collection using the above code.

enter image description here

Max Leske
  • 5,007
  • 6
  • 42
  • 54
babucr
  • 11
  • 5

1 Answers1

0

If you do not know what the code does, it is probably best to research it before attempting to use it or come up with your own solution. As far as I can tell, you are attempting to add an additional property to a UserControl that inherits DataGrid.

You have two options:

  1. Create a DependencyProperty (the best choice, in my opinion).
  2. Create a normal property

Here's a couple links to help you get started:

What is the difference between Property and Dependency Property

When should I use dependency properties in WPF?

Community
  • 1
  • 1