Home Forums WPF controls Xceed DataGrid for WPF Case 107631:how to bind the Dependency Properties at Colum

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23492 |

    I am attaching the Customer Class file below, it contains 4 Dependency Properties (Name,Surname,Age,Sex), of which I want to show suppose ONLY 2 or 3 in the Xceed Grid. But I don’t want to bind it through the code. I want it through the XAML file. I want to keep my Code as empty as possible.

    Please advice me how to bind the Dependency Properties at Runtime at Column Level in the Xceed Grid.

    Customer.cs
    ************
    public class Customer : DependencyObject
    {
    public Customer()
    {

    }

    #region Dependent Properties
    public static readonly DependencyProperty NameProperty =
    DependencyProperty.Register(“Name”, typeof(string), typeof(Customer));

    public static readonly DependencyProperty SurNameProperty =
    DependencyProperty.Register(“SurName”, typeof(string), typeof(Customer));

    public static readonly DependencyProperty AgeProperty =
    DependencyProperty.Register(“Age”, typeof(string), typeof(Customer));

    public static readonly DependencyProperty SexProperty =
    DependencyProperty.Register(“Sex”, typeof(string), typeof(Customer));

    #endregion

    #region Public Properties
    public string Name
    {
    get { return (string)GetValue(NameProperty); }
    set { SetValue(NameProperty, value); }
    }

    public string SurName
    {
    get { return (string)GetValue(SurNameProperty); }
    set { SetValue(SurNameProperty, value); }
    }

    public string Age
    {
    get { return (string)GetValue(AgeProperty); }
    set { SetValue(AgeProperty, value); }
    }

    public string Sex
    {
    get { return (string)GetValue(SexProperty); }
    set { SetValue(SexProperty, value); }
    }
    #endregion

    public Customer(string name, string surname, string age, string sex)
    {
    Name = name;
    SurName = surname;
    Age = age;
    Sex = sex;
    }

    internal void Add(Customer customer)
    {
    throw new Exception(“The method or operation is not implemented.”);
    }
    }

    And my XAML.CS should only look like
    **********************************
    private ObservableCollection<Customer> cust_items;

    public ObservableCollection<Customer> CustomerDet
    {
    get
    {
    if (cust_items == null)
    {
    return new ObservableCollection<Customer>();
    }
    return cust_items;
    }
    }

    Imported from legacy forums. Posted by Amitava (had 1905 views)

    Xceed Support
    Member
    Post count: 5658

    There is a property called AutoCreateColumns on the DataGridControl. When set to false, columns will not be automatically created.

    You can then only create the columns you want in XAML.

    An alternate route is to leave AutoCreateColumns to True bu specify a Column in XAML for each filed you DO NOT want to show, and set their “Visible” property to False (effectivelly hiding the columns).

    Imported from legacy forums. Posted by Marcus [Xceed] (had 3073 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.