开发者

Creating Data template for ListBox for WindowPhone7

Is it possible to c开发者_JAVA百科reate data-template for the list box in WP7 using C# code instead of XAML??


You can't instantiate a DataTemplate in code in the same way that you can for regular controls, but you can use the XamlReader.Load() method to create a DataTemplate from a XAML string:

string xaml = @"<DataTemplate
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <!-- Template content goes here. -->
</DataTemplate>";
var dt = (DataTemplate)XamlReader.Load(xaml);

Be sure to add any additional namespaces that you might need. The answer to this question also shows that you can create bindings in the DataTemplate in the same way: Creating a Silverlight DataTemplate in code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜