views:

89

answers:

2

I have a DataGrid in my silverlight app that has a few columns. A couple basic columns bound with no issues. One column has a UserControl in it and the XAML is as follows:


<data:DataGridTemplateColumn Header="" CanUserSort="True" Width="107">
    <data:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <local:StaticPageEnlistment EnlistmentName="{Binding SiteName}" Width="400" Height="150"/>
        </DataTemplate>
    </data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>

So I have a public property that's a string called EnlistmentName that I have bound to the SiteName value. I use this same "{Binding SiteName}" in all my other colums with no issues, why can't the user control accept the same binding string?

A: 

At a guess you haven't implemented the EnlistmentName as a DependencyProperty. You would do that like this in your StaticPageEnlistment UserControl like this:-

    public string EnlistmentName
    {
        get { return GetValue(EnlistmentNameProperty) as string; }
        set { SetValue(EnlistmentNameProperty, value); }
    }

    public static readonly DependencyProperty EnlistmentNameProperty =
            DependencyProperty.Register(
                    "EnlistmentName",
                    typeof(string),
                    typeof(StaticPageEnlistment ),
                    new PropertyMetadata(null));
AnthonyWJones
Anthony, you were 31 seconds quicker :-)
Timores
Thanks for the suggestion. I tried that and it doesn't appear to have solved it. Besides, when I hard code a string into the property like EnlistmentName="Test String" the binding works fine so I don't think it's an isdsue with the user control not allowing binding.
Eric
Wait. Never mind...it's working now...I had to change my property to be the same as your as now it works. Thanks!
Eric
A: 

Is EnlistmentName a DependencyProperty ? According to MSDN, the target of a binding must be a DependencyProperty.

Timores