datatemplate issue in silverlight(when assigning value to property)
Consider this code:
public class customlistbox : ListBox
{
public customlistbox()
{
this.itemtemplate = this.gettemplate();
}
private string gettemplate()
{
return ".......<locall:CustomGrid Background='" + Background.Color + "' ParentReference='" + this + "' > "....."
}
}
'ParentReference' is 开发者_如何学JAVAa property which is of type customlistbox. but i give ParentReference='" + this + "', it shows error. how can i give value for 'ParentReference' in such case??
This is failing because you're passing a string to a property which is a DataTemplate
.
You could try using a XamlReader
to load the string as xaml, but for the sake of just specifying a color within the template I'd define the template in XAML and then bind the value you want for the color.
精彩评论