Hi,
I'd like to show/hide the some columns (Fields in XamDataGrid) depending on what data fields are available in the view model (DataSource for the grid) in xaml. Can you show me some examples on how to do that? thanks.
Basically I'd like to do something like below, but how cal I pass the binding source?
<
igDP:Field Label="My Column" Name="MyProperty" Visibility="{Binding ????}"/>
Do field in a XamDataGrid mimic how Columns behave in DataGrid? Because even though a column is not in the Visual Tree of DataGrid you are still able to bind do it with the following:
<DataGrid Name="dgvMain"><DataGrid.Resources><rent:BindingProxy x:Key="proxy" Data="{Binding}" /></DataGrid.Resources><DataGrid.Columns><DataGridTextColumn x:Name="dgcFooBar" Visibility="{Binding Path=Data.ShowFooBar}" /></DataGrid.Columns></DataGrid>
BindingProxy looks like this:
Public Class BindingProxy Inherits Freezable#Region "Overrides of Freezable"
Protected Overrides Function CreateInstanceCore() As Freezable Return New BindingProxy() End Function
#End Region
Public Property Data() As Object Get Return DirectCast(GetValue(DataProperty), Object) End Get Set(value As Object) SetValue(DataProperty, value) End Set End Property
' Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc... Public Shared ReadOnly DataProperty As DependencyProperty = DependencyProperty.Register("Data", GetType(Object), GetType(BindingProxy), New UIPropertyMetadata(Nothing)) End Class
Would this method work for binding with XamDataGrid??
Please note that I am using 15.1
Fields are not part of the visual tree of the XamDataGrid, so you cannot use bindings. You could handle the property changed event of your underlying source class and set the visibility manually if this is not an option for you.
Thanks, I think it works this way.
BUT, it looks like hack to me, XamDataGrid really should have a built in way to pass its data context to the Field, without requirign application to have special code to add the data context to the application resource...
Is it possible to bind the Visibility of a field to the DataItem for the field?
Hello,
You can find a sample solution for this issue here.
Hope this helps.