1
votes

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?

2

2 Answers

0
votes

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));
0
votes

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