How to create DataSource dependency property on a wpf User Control

Posted by Michael Hedgpeth on Stack Overflow See other posts from Stack Overflow or by Michael Hedgpeth
Published on 2009-06-05T20:09:21Z Indexed on 2010/04/30 8:27 UTC
Read the original article Hit count: 184

Filed under:
|

I have a user control that wraps a grid. I want to be able to set the underlying grid's data source, but through the user control, like this:

<my:CustomGrid DataSource="{Binding Path=CollectionView}" />

I have set this up in the grid like this:

    private static readonly DependencyProperty DataSourceProperty 
        = DependencyProperty.Register("DataSource", typeof(IEnumerable), typeof(CustomGrid));

    public IEnumerable DataSource
    {
        get { return (IEnumerable)GetValue(DataSourceProperty); }
        set
        {
            SetValue(DataSourceProperty, value);
            underlyingGrid.DataSource = value;
        }
    }

But this doesn't work (it doesn't give me an error either). The data source is never set. What am I missing?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf