开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜