This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Like this:
!? |
|
|
Hello Nestor In WPF, when setting up a binding in XAML, the target of the binding must be a framework element. Our DataGridColumn is a model object which is why this does not work in xaml. I have considered changing this to a framework element, but this is something we can not do until a major version as it will introduce a few breaking changes. For now you will need to either set up the columns in code such as in a view model (which isn't too bad considering DataGridColumn is a just a model object), or you'd need to access the DataGridColumn from code to manipulate the property or set a binding. Jason Fauchelle |
|
|
What do you mean by "For now you will need to either set up the columns in code such as in a view model (which isn't too bad considering DataGridColumn is a just a model object)" ? Can you bind the collection of columns to the view model? N |
|
|
Hello Nestor Yes, since the Columns property is writeable, you can bind the Columns property to a property in your view-model that provides an ObservableCollection of DataGridColumn. Since DataGridColumn is a model object, not a control, there is no worry about infecting your view-model with UI controls. The DataGridColumn does however have a couple of properties of type Brush and DataTemplate. If you do not want to have DataGridColumn objects in your view-model, you could create your own model class representing a column and expose a collection of these custom objects. Then use a converter or an attached property to convert and sync up your column model objects to a collection of DataGridColumn. Another option that may be less work is to create an attached property which you could set on the DataGrid which binds to the property that effects the visibility of the column. Within the attached property you can have the code that looks into the DataGrid, finds the desired column and then changes the visibility. Jason Fauchelle |
|
|
Excellent. Thanks for the great info. |
|