Hi,
I am trying to bind a unbound column to a visibility property in the MVVM format, looks like it doesn't work. Can I not bind the visibility of the unbound field?
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields> <igDP:UnboundField Name="View" Visibility="{Binding ViewVisible}"> <igDP:UnboundField.Settings> <igDP:FieldSettings AllowResize="False" AllowGroupBy="False" AllowRecordFiltering="False" AllowSummaries="False" LabelTextAlignment="Center" Width="75" CellValuePresenterStyle="{StaticResource CellButtonStyle}"/> </igDP:UnboundField.Settings> </igDP:UnboundField></igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
I need to bind the label on UnboundField in xamdatagrid like:
igDP:UnboundField Label="{Binding abc[0]}"
where abc is an ObservableCollection. But its not showing anything in the lable. Please help.
Thanks :)
After another few hours searching the internet, I found Thomas Levesques Blog.He gives a really nice solution:http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/
So I just setted up a BindingProxy-Class and integrated it into my xaml:
...<igDP:XamDataGrid.Resources> <local:BindingProxy x:Key="proxy" Data="{Binding}"></igDP:XamDataGrid.Resources>...<igDP:Field Label="Name" Name="Name" Visibility="{Binding Data.IsNameVisible, Source={StaticResource proxy}, Converter={StaticResource boolToVis}}"/><igDP:UnboundField Label="Age" BindingPath="User.Age" Visibility="{Binding Data.IsAgeVisible, Source={StaticResource proxy}, Converter={StaticResource boolToVis}}"/>...
Hi Krasimir,
is there a way to bind the Visibility to a RelativeSource?
I am binding the ViewModel to the DataContext of my UserControl programmatically, so I do not really want another instance of my ViewModel in the resources of the UserControl.
Thanks a lot,cheers!
Hello Arpita,
I am just checking if you require any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Thank you for your post. I have been looking into the behavior that you are having and the reason for the Binding for the Visibility property of the Fields and UnboundFields to not work is that you are using binding, which does not have a Source defined. The Field and UnboundField classes are not actually a visual elements. Since the Field and the UnboundField does not derives from the FrameworkElement class, they does not expose a DataContext property. In order to bind the properties of those two classes, you can use the Source property of the binding. You can define an instance of your View Model in the Resources of the Window and to use that object to bind the Visibility properties of the Fields. I have created a sample application for you, that shows how you can implement this approach.
Please let me know if I can assist you with anything else.