如何在代码中定义一个DataTemplate? [英] How to define a DataTemplate in code?

查看:237
本文介绍了如何在代码中定义一个DataTemplate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能创建一个的DataTemplate 中的代码(使用C#),然后添加一个控制到的DataTemplate

How can I create a DataTemplate in code (using C#) and then add a control to that DataTemplate?

<data:DataGrid.RowDetailsTemplate>
    <DataTemplate>
        <Border>
            <Border Margin="10" Padding="10" BorderBrush="SteelBlue" 
                 BorderThickness="3" CornerRadius="5">
                <TextBlock Text="{Binding Description}" TextWrapping="Wrap" 
                     FontSize="10">
                </TextBlock>
            </Border>
        </Border>
    </DataTemplate>
</data:DataGrid.RowDetailsTemplate>



我使用Sivlerlight。

I am using Sivlerlight.

推荐答案

据我所知,在Silverlight创建一个的DataTemplate 的唯一方法是使用的 XamlReader 。基本上你只想通过它的XAML作为一个字符串,它会给你回一个的DataTemplate 。拜伦的解决方案将适用于WPF,但Silverlight的(据我所知)不支持 FrameworkElementFactory

As far as I know, the only way to create a DataTemplate in Silverlight is to use XamlReader. Basically you would just pass it the XAML as a string and it will give you back a DataTemplate. Byron's solution would apply to WPF but Silverlight (to the best of my knowledge) does not support FrameworkElementFactory.

< A HREF =http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx相对=nofollow>斯科特·莫里森:定义的Silverlight的DataGrid在运行时

记的选项#2 DataGridTemplateColumn

这篇关于如何在代码中定义一个DataTemplate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆