I have the following XAML snippet.<igDock:ContentPane x:Class="...." .... xmlns:ig=”http://schemas.infragistics.com/xaml” Header=”{Binding Name}”> <ig:XamGrid ItemsSource=”{Binding DataTable}” ...> <ig:XamGrid.PagerSettings> <ig:PagerSettings AllowPaging=”Bottom” PageSize=”{Binding MaxRecordCount}” /> </ig:XamGrid.PagerSettings> </ig:XamGrid></igDock:ContentPane>This XAML snippet shows three binding. One for the Header of the ContentPane, a second for the ItemsSource of the XamGrid and a third for the PageSize of the PagerSettings. The Binding for the Header and ItemsSource work fine but the Binding for the PageSize does not. I see the following Binding Error in the Output window.System.Windows.Data Error: 2 : Cannot find governing FrameworkElement for FrameworkContentElement for target element. BindingExpression:Path=MaxRecordCount; DataItem=null; target element is ‘PagerSettings’ (HashCode=xxxxxxxxx); target property is ‘PageSize’ (type ‘Int32’)I have the correct properties in my ViewModel and they are correctly using the NotifyPropertyChanged events.Can anyone tell me how to correct this Binding Error?
Hello Eric,
Thank you for your post. I have been looking into it and I have created a sample project for you with the functionality you want. Basically I create an instance of the ViewModel in the Window’s Resources and set it as Binding’s Source, because the DataContext in the PagerSettings is null. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Ok I was able to solve this with the following XAML. I did set the DataContext all over the place but its working. Thanks.<igDock:ContentPane .... Header={Binding Name}" .... > <igDock:ContentPane.Resources> <vm:AttributeTableViewModel2 x:Key="AttributeTableViewModel" /> </igDock:ContentPane.Resources> <igDock:ContentPane.DataContext> <Binding Source="{StaticResource AttributeTableViewModel" /> <igDock:ContentPane.DataContext> <Grid DataContext="{StaticResource AttributeTableViewModel}"> <ig:XamGrid DataContext="{StaticResource AttributeTableViewModel}"> <ig:XamGrid.PagerSettings> <ig:PagerSettings PageSize="{Binding Source={StaticResource AttributeTableViewModel}, Path=MaxRecordCount}" /> </ig:XamGrid.PagerSettings> </ig:XamGrid> <Grid>
Thanks for the reply. The example code you posted did help but its solution caused another binding to not work. If you notice in my code snippet I have a Header={Binding Name}" in the root XAML node. Since the DataContext is only set at the XamGrid level the Binding in the root XAML node fails because its DataContext is null. Is there a way to set the DataContext in the root XAML node and still have the Binding for PageSize work? I have been playing around with it but no luck so far.
Thanks,
-eric