Welcome to the Xceed Community Sign in | Join | Help
Community Search  

DataGridCollectionViewSource - Binding Source

Sort Posts: Previous Next
  •  06-24-2008, 1:11 PM Post no. 13185

    DataGridCollectionViewSource - Binding Source

    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

  •  06-25-2008, 6:59 PM Post no. 13227 in reply to 13185

    Re: DataGridCollectionViewSource - Binding Source

    Application.Current (App.xaml.cs  ) is just the location I chose to place the property that exposes my data source. That said, you can have your property anywhere as long as the grid has access to it. For example, if you have a Window1 that contains  your grid, you could do an AncestorType binding to find the window and get the property (1). Another option would be in the window's constructor to set the window's DataContext to itself and access the properties directly in the binding (2).

    1- {Binding RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}, Path=MyProperty}

    This binding assumes that you have declared an xmlns named local for your local namespace.

    2- In the ctor of the window:

    this.DataContext = this;

    {Binding Path=MyProperty}


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.