我有以下内容DataTemplate
:
<DataTemplate x:Key="ButtonTemplate">
<Button Click="Cell_Click">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<TextBlock x:Name="TBlock" />
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
我将其DataTemplate
用作,但是当我添加新列时GridViewColumn.CellTemplate
,我必须动态绑定 的Text
属性:TextBlock
GridViewColumn column = new GridViewColumn();
column.CellTemplate = Resources["ButtonTemplate"] as DataTemplate;
// How to get the TBlock (TextBlock) of CellTemplate and bind its property here?
MyGridView.Columns.Add(column);
我该怎么办?谢谢。