Hi all, first post!
I'd like to start off by saying thanks to everyone else for the support provided on these forums, it has been invaluable!
I'm having an issue trying to bind a DataGridCollectionViewSource Source Property to a Property on my UserControl. I've used the DataGrid in combination with a DataGridCollectionViewSource on a number of Pages, but they've all been bound to a static Application property.
I have a UserControl that has a DataTable Property, "ReportData", that I want to bind a DataGridCollectionViewSource to:
Partial Public Class ctrlReport
Implements INotifyPropertyChanged
Private _dTblReport As IndividualWPackReports.ComponentReportDataTable
Public ReadOnly Property ReportData() As IndividualWPackReports.ComponentReportDataTable
Get
Return _dTblReport
End Get
End Property
====================================
<UserControl x:Class="ctrlComponentReport"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:compModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:conv="clr-namespace:Converters"
x:Name="ReportControl"
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\PageReports\TableViewTemplates.xaml"/>
</ResourceDictionary.MergedDictionaries>
<conv:NoOpConverter x:Key="noopconv"/>
<xcdg:DataGridCollectionViewSource
x:Key="dgcvs"
Source="{Binding ElementName=ReportControl, Path=ReportData, Converter={StaticResource noopconv},diagnostics:PresentationTraceSources.TraceLevel=High}">
This doesn't work. I've tried initializing the datatable, and filling it before the component is initalized, I've tried using a converter to debug it (The break point set on the Convert method is never reached) , all to no avail. Here is the trace output from the binding, if it helps:
System.Windows.Data Warning: 47 : Created BindingExpression (hash=59311937) for Binding (hash=38600745)
System.Windows.Data Warning: 49 : Path: 'ReportData'
System.Windows.Data Warning: 51 : BindingExpression (hash=59311937): Default mode resolved to OneWay
System.Windows.Data Warning: 52 : BindingExpression (hash=59311937): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 53 : BindingExpression (hash=59311937): Attach to Xceed.Wpf.DataGrid.DataGridCollectionViewSource.Source (hash=51791499)
System.Windows.Data Warning: 55 : BindingExpression (hash=59311937): Use Framework mentor <null>
System.Windows.Data Warning: 58 : BindingExpression (hash=59311937): Resolving source
System.Windows.Data Warning: 60 : BindingExpression (hash=59311937): Framework mentor not found
System.Windows.Data Warning: 56 : BindingExpression (hash=59311937): Resolve source deferred
If I create a ListView on the same UserControl, and give it the same binding, it works.
When I change the Source property on the DataGridCollectionViewSource to a relative binding:
Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ReportData, Converter={StaticResource noopconv},diagnostics:PresentationTraceSources.TraceLevel=High}">
It works?!?
Am I missing something? Any light someone could shed on the issue would be greatly appreciated!
Cheers