开发者

Creating Data template for ListBox for WindowPhone7

开发者 https://www.devze.com 2023-02-06 19:43 出处:网络
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 cont

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

精彩评论

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

关注公众号