我有以下DataTemplate
:綁定的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
,但我必須動態綁定TextBlock
的Text
屬性,當我添加一個新的列:
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);
我該怎麼辦?謝謝。
什麼是我必須解析的字符串? – Nick
@Nick:在XAML中包含您的數據模板的字符串,在SO上搜索方法名稱,您將找到示例。 –